﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
 
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CommonPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string Flag = string.Empty;
        string OrderId = string.Empty;
        string DineTableId = string.Empty;
        string DishId = string.Empty;
        string HotelId = string.Empty;
        string U_Id = string.Empty;
        string array = string.Empty;
        string DishState = string.Empty;
        string Num = string.Empty;
        string IsDisplay = string.Empty;
        string jcrs = string.Empty;
        string opration = Request.QueryString["opration"].ToString();
        #region 操作标识
        switch (opration)
        {
            case "login":
                string name = Request.QueryString["LoginName"].ToString();
                string pwd = Request.QueryString["LoginPasswd"].ToString();
                Response.Write(login(name, pwd));
                break;
            case "getOrderList":
                Flag = Request.QueryString["flag"].ToString();
                Response.Write(getOrderList(Flag));
                break;
            case "getTableType":
                Flag = Request.QueryString["flag"].ToString();
                Response.Write(getTableType(Flag));
                break;
            case "getHandleType":
                Flag = Request.QueryString["flag"].ToString();
                Response.Write(getHandleType(Flag));
                break;
            case "openDineTable":
                HotelId = Request.QueryString["HotelId"].ToString();
                string HotelName = Request.QueryString["HotelName"].ToString();
                DineTableId = Request.QueryString["DineTableId"].ToString();
                string Category = Request.QueryString["Category"].ToString();
                 jcrs = Request.QueryString["jcrs"].ToString();
                Response.Write(openDineTable(HotelId, HotelName, DineTableId, Category, jcrs));
                break;
            case "getCookbookCategory":
                Response.Write(getCookbookCategory());
                break;
            case "getCookbookList":
                Flag = Request.QueryString["flag"].ToString();
                Response.Write(getCookbookList(Flag));
                break;
            case "updateOrderCookBook":
                OrderId = Request.QueryString["OrderId"].ToString();
                array = Request.QueryString["array"].ToString();
                U_Id = Request.QueryString["U_Id"].ToString();
                string StateFlag = Request.QueryString["StateFlag"].ToString();
                Response.Write(updateOrderCookBook(OrderId, array, U_Id, StateFlag));
                break;
            case "cancelDineTable":
                HotelId = Request.QueryString["HotelId"].ToString();
                OrderId = Request.QueryString["OrderId"].ToString();
                Response.Write(cancelDineTable(HotelId, OrderId));
                break;
            case "getOrderDetail":
                OrderId = Request.QueryString["OrderId"].ToString();
                Response.Write(getOrderDetail(OrderId));
                break;
            case "updateOrderState":
                HotelId = Request.QueryString["HotelId"].ToString();
                OrderId = Request.QueryString["OrderId"].ToString();
                jcrs = Request.QueryString["jcrs"].ToString();
                Response.Write(updateOrderState(HotelId, OrderId, jcrs));
                break;
            case "updateOrderBookedDate":
                OrderId = Request.QueryString["OrderId"].ToString();
                string BookedDate = Request.QueryString["BookedDate"].ToString();
                string RetentionTime = Request.QueryString["RetentionTime"].ToString();
                Response.Write(updateOrderBookedDate(OrderId, BookedDate, RetentionTime));
                break;
            case "getOrderDetails":
                OrderId = Request.QueryString["OrderId"].ToString();
                Response.Write(getOrderDetails(OrderId));
                break;
            case "updateCookWeight":
                OrderId = Request.QueryString["OrderId"].ToString();
                DishId = Request.QueryString["DishId"].ToString();
                DishState = Request.QueryString["DishState"].ToString();
                Response.Write(updateCookWeight(OrderId, DishId, DishState));
                break;
            case "cancelCookbook":
                OrderId = Request.QueryString["OrderId"].ToString();
                DishId = Request.QueryString["DishId"].ToString();
                Num = Request.QueryString["Num"].ToString();
                IsDisplay = Request.QueryString["IsDisplay"].ToString();
                Response.Write(cancelCookbook(OrderId, DishId, Num, IsDisplay));
                break;
            case "getCookList":
                Flag = Request.QueryString["flag"].ToString();
                Response.Write(getCookList(Flag));
                break;
            case "updateCookState2":
                OrderId = Request.QueryString["OrderId"].ToString();
                DishId = Request.QueryString["DishId"].ToString();
                string arrOrderId = Request.QueryString["arrOrderId"].ToString();
                string arrDishId = Request.QueryString["arrDishId"].ToString();
                Response.Write(updateCookState2(OrderId, DishId, arrOrderId, arrDishId));
                break;
            case "updateCookState3":
                DishId = Request.QueryString["DishId"].ToString();
                string CookChef = Request.QueryString["CookChef"].ToString();
                Response.Write(updateCookState3(DishId, CookChef));
                break;
            case "getDishList":
                Flag = Request.QueryString["flag"].ToString();
                Response.Write(getDishList(Flag));
                break;
            case "updateDishState":
                OrderId = Request.QueryString["OrderId"].ToString();
                DishId = Request.QueryString["DishId"].ToString();
                Num = Request.QueryString["Num"].ToString();
                IsDisplay = Request.QueryString["IsDisplay"].ToString();
                Response.Write(updateDishState(OrderId, DishId, Num, IsDisplay));
                break;
            case "getDineTable":
                OrderId = Request.QueryString["OrderId"].ToString();
                DineTableId = Request.QueryString["DineTableId"].ToString();
                Response.Write(getDineTable(OrderId, DineTableId));
                break;
            case "updateOrderDineTable":
                OrderId = Request.QueryString["OrderId"].ToString();
                DineTableId = Request.QueryString["DineTableId"].ToString();
                string newDineTableId = Request.QueryString["newDineTableId"].ToString();
                Response.Write(updateOrderDineTable(OrderId, DineTableId, newDineTableId));
                break;
            case "getDineTableList":
                Flag = Request.QueryString["flag"].ToString();
                Response.Write(getDineTableList(Flag));
                break;
            case "cleanDineTable":
                OrderId = Request.QueryString["OrderId"].ToString();
                DineTableId = Request.QueryString["DineTableId"].ToString();
                Response.Write(cleanDineTable(OrderId, DineTableId));
                break;
            case "getUserInfo":
                Response.Write(getUserInfo());
                break;
            case "getCashierList":
                Flag = Request.QueryString["flag"].ToString();
                Response.Write(getCashierList(Flag));
                break;
            case "OrderPaying":
                U_Id = Request.QueryString["U_Id"].ToString();
                OrderId = Request.QueryString["OrderId"].ToString();
                DineTableId = Request.QueryString["DineTableId"].ToString();
                string OrderAmount = Request.QueryString["OrderAmount"].ToString();
                string DisAmount = Request.QueryString["DisAmount"].ToString();
                string RecAmount = Request.QueryString["RecAmount"].ToString();
                string AccAmount = Request.QueryString["AccAmount"].ToString();
                Response.Write(OrderPaying(U_Id, OrderId, DineTableId, OrderAmount, DisAmount, RecAmount, AccAmount));
                break;
            case "getOrderQueryList":
                string beginDate = Request.QueryString["beginDate"].ToString();
                string endDate = Request.QueryString["endDate"].ToString();
                Response.Write(getOrderQueryList(beginDate, endDate));
                break;
            case "UpdateNum":
                string DetailId = Request.QueryString["DetailId"].ToString();
                Num = Request.QueryString["Num"].ToString();
                Response.Write(UpdateNum(DetailId, Num));
                break;
            case "setCookbook":
                OrderId = Request.QueryString["OrderId"].ToString();
                Response.Write(setCookbook(OrderId));
                break;
            case "setBindUser":
                OrderId = Request.QueryString["OrderId"].ToString();
                string Mobile = Request.QueryString["Mobile"].ToString();
                Response.Write(setBindUser(OrderId, Mobile));
                break;
            case "UpdatePassWord":
                string oldpwd = Request.QueryString["oldpwd"].ToString();
                string newpwd = Request.QueryString["newpwd"].ToString();
                Response.Write(UpdatePassWord(oldpwd, newpwd));
                break; 
            default:
                break;
        }
        #endregion
    }

   /// <summary>
   /// 修改密码
   /// </summary>
   /// <param name="oldpwd"></param>
   /// <param name="newpwd"></param>
   /// <returns></returns>
    private string  UpdatePassWord(string oldpwd, string newpwd)
    { 
        var sb = new StringBuilder();
        string url = string.Empty;
        if (oldpwd.Equals("") || newpwd.Equals(""))
        {
            sb.Append("{\"Success\":false,\"Msg\":\"密码不能为空！\",\"Url\":\"\"}");
            return sb.ToString();
        }
        if (DESEncrypt.Encrypt(oldpwd) != Session[CookieHelp.SESSION_H_UserPwd].ToString())
        {
            sb.Append("{\"Success\":false,\"Msg\":\"旧密码输入错误！\",\"Url\":\"\"}");
            return sb.ToString();
        } 
        var strSql = new StringBuilder();
        strSql.Append("Update H_Hotel_Users Set  Password=@Password  where H_UID=@H_UID;"); 
        SqlParameter[] parameters = { 
            new SqlParameter("@H_UID", SqlDbType.NVarChar, 200),
            new SqlParameter("@Password", SqlDbType.NVarChar, 100)
        };
        parameters[0].Value = Session[CookieHelp.SESSION_H_UID].ToString();
        parameters[1].Value = DESEncrypt.Encrypt(newpwd);

         int flag = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
         if (flag > 0)
           {
               sb.Append("{\"Success\":true,\"Msg\":\"密码修改成功，请重新登录！\",\"Url\":\"login.html\"}");
               return sb.ToString();
           }
       return "";
    }

    /// <summary>
    /// 酒店人员登录
    /// </summary>
    /// <param name="name">用户ID</param>
    /// <param name="pwd">用户密码</param>
    /// <returns>返回Json数据</returns>
    private string login(string name, string pwd)
    {
        StringBuilder sb = new StringBuilder();
        string url = string.Empty;
        if (name.Equals("") || pwd.Equals(""))
        {
            sb.Append("{\"Success\":false,\"Msg\":\"用户名和密码不能为空！\",\"Url\":\"\"}");
            return sb.ToString();
        }

        StringBuilder strSql = new StringBuilder();
        strSql.Append("select HotelId, H_Name, H_UID, H_UserName, Password, RoleIds, Status, DeptId ");
        strSql.Append("from H_Hotel_Users u,H_Hotels h ");
        strSql.Append("where u.HotelId=h.H_id ");
        strSql.Append("and H_UID=@H_UID ");
        strSql.Append("and Password=@Password ");
        strSql.Append("and Status='0'");
        SqlParameter[] parameters = { 
            new SqlParameter("@H_UID", SqlDbType.NVarChar, 200),
            new SqlParameter("@Password", SqlDbType.NVarChar, 100)
        };
        parameters[0].Value = name;
        parameters[1].Value = DESEncrypt.Encrypt(pwd);

        DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
        if (ds.Tables[0].Rows.Count > 0)
        {
            url = HotelRoleHtmlString(ds.Tables[0].Rows[0]["RoleIds"].ToString());
            if (string.IsNullOrEmpty(url))
            {
                sb.Append("{\"Success\":false,\"Msg\":\"登录失败！该用户不具备相关角色！\",\"Url\":\"\"}");
                return sb.ToString();
            }
            else
            {
                Session[CookieHelp.SESSION_HotelId] = ds.Tables[0].Rows[0]["HotelId"].ToString();
                Session[CookieHelp.SESSION_H_Name] = ds.Tables[0].Rows[0]["H_Name"].ToString();
                Session[CookieHelp.SESSION_H_UID] = ds.Tables[0].Rows[0]["H_UID"].ToString();
                Session[CookieHelp.SESSION_H_UserName] = ds.Tables[0].Rows[0]["H_UserName"].ToString();
                Session[CookieHelp.SESSION_RoleIds] = ds.Tables[0].Rows[0]["RoleIds"].ToString();
                Session[CookieHelp.SESSION_RoleId] = url.Split('|')[1];
                Session[CookieHelp.SESSION_RoleName] = HotelRolesHtmlString(ds.Tables[0].Rows[0]["RoleIds"].ToString());
                Session[CookieHelp.SESSION_DeptId] = ds.Tables[0].Rows[0]["DeptId"].ToString();
                Session[CookieHelp.SESSION_H_UserPwd] = ds.Tables[0].Rows[0]["Password"].ToString();

                sb.Append("{\"Success\":true,\"Msg\":\"登录成功！\",\"Url\":\"" + url.Split('|')[0] + "\"}");
                return sb.ToString();
            }
        }
        else
        {
            sb.Append("{\"Success\":false,\"Msg\":\"用户名或密码错误！\",\"Url\":\"\"}");
            return sb.ToString();
        }
    }

    /// <summary>
    /// 酒店角色
    /// </summary>
    /// <param name="hotelRoleIds">权限ID</param>
    /// <returns>返回Json数据</returns> 
    private String HotelRoleHtmlString(string hotelRoleIds)
    {
        string url = string.Empty;
        string RoleId = string.Empty;
        for (int i = 0; i < hotelRoleIds.Split(',').Length; i++)
        {
            RoleId = hotelRoleIds.Split(',')[i];
            if (RoleId == "1" || RoleId == "2")
            {
                url = "manager.html|" + RoleId;
                break;
            }
            else if (RoleId == "3")
            {
                url = "clean.html|" + RoleId;
                break;
            }
            else if (RoleId == "4")
            {
                url = "cashier.html|" + RoleId;
                break;
            }
            else if (RoleId == "5")
            {
                url = "cook.html|" + RoleId;
                break;
            }
            else if (RoleId == "6")
            {
                url = "senddish.html|" + RoleId;
                break;
            }
        }
        return url;
    }

    /// <summary>
    /// 获取登录用户角色名称
    /// </summary>
    /// <param name="hotelRoleIds">角色ID</param>
    /// <returns>返回Json数据</returns>
    public string HotelRolesHtmlString(string hotelRoleIds)
    {
        hotelRoleIds = hotelRoleIds.Replace("1", "酒店管理员");
        hotelRoleIds = hotelRoleIds.Replace("2", "部长");
        hotelRoleIds = hotelRoleIds.Replace("3", "服务员");
        hotelRoleIds = hotelRoleIds.Replace("4", "收银员");
        hotelRoleIds = hotelRoleIds.Replace("5", "厨师");
        hotelRoleIds = hotelRoleIds.Replace("6", "传菜员");
        return hotelRoleIds;
    }

    /// <summary>
    /// 根据时间获取订单数据
    /// </summary>
    /// <param name="Flag">时间:今天,明天,后天,其他时间</param>
    /// <returns>返回Json数据</returns>
    private string getOrderList(string Flag)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            StringBuilder strSql = new StringBuilder();
            //strSql.Append("select r.Id,r.OrderState,r.ContactUser,r.ContactMobile,SUBSTRING(r.ReserveDate,6,6)+r.ReserveTime Reserve,r.DineNum,t.Category,t.Name ");
            strSql.Append("select r.Id,r.OrderState,r.ContactUser,r.ContactMobile,CONVERT(varchar(16),r.OrderTime,20) Reserve,r.DineNum,t.Category,t.Name ");
            strSql.Append("from D_Order r,H_Hotel_Seat t ");
            strSql.Append("where r.H_Id = t.HotelId ");
            strSql.Append("and r.DineTable = t.Id ");
            strSql.Append("and r.OrderState in (2,4) ");
            strSql.Append("and r.H_Id = '" + Session[CookieHelp.SESSION_HotelId] + "' ");
            if (Flag != "")
            {
                if (Flag == "Today")
                {
                    //strSql.Append(" and replace(replace(replace(r.ReserveDate,'年','-'),'月','-'),'日','') = CONVERT(varchar(10), GETDATE(), 23) ");
                    strSql.Append(" and CONVERT(varchar(10), OrderTime, 23) = CONVERT(varchar(10), GETDATE(), 23) ");
                }
                else if (Flag == "Tomorrow")
                {
                    //strSql.Append(" and replace(replace(replace(r.ReserveDate,'年','-'),'月','-'),'日','') = CONVERT(varchar(10), GETDATE()+1, 23) ");
                    strSql.Append(" and CONVERT(varchar(10), OrderTime, 23) = CONVERT(varchar(10), GETDATE()+1, 23) ");
                }
                else if (Flag == "Postnatal")
                {
                    //strSql.Append(" and replace(replace(replace(r.ReserveDate,'年','-'),'月','-'),'日','') = CONVERT(varchar(10), GETDATE()+2, 23) ");
                    strSql.Append(" and CONVERT(varchar(10), OrderTime, 23) = CONVERT(varchar(10), GETDATE()+2, 23) ");
                }
                else if (Flag == "OtherTime")
                {
                    //strSql.Append(" and CONVERT(varchar(10), GETDATE()+3, 23)<=replace(replace(replace(r.ReserveDate,'年','-'),'月','-'),'日','') ");
                    strSql.Append(" and CONVERT(varchar(10), GETDATE()+3, 23)<= CONVERT(varchar(10), OrderTime, 23) ");
                }
            }
            strSql.Append(" order by r.OrderTime desc ");

            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            StringBuilder sb = new StringBuilder();
            sb.Append("{\"Today\":\"" + System.DateTime.Now.ToString("yyyy-MM-dd") + "\",\"Tomorrow\":\"" + System.DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + "\",\"Postnatal\":\"" + System.DateTime.Now.AddDays(2).ToString("yyyy-MM-dd") + "\",\"HotelId\":\"" + Session[CookieHelp.SESSION_HotelId] + "\"");
            string OrderState = string.Empty;
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append(",\"Success\":true,\"Total\":\"" + ds.Tables[0].Rows.Count + "\",");
                sb.Append("\"List\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i]["OrderState"].ToString() == "2")
                    {
                        OrderState = "tbldetail";
                    }
                    else if (ds.Tables[0].Rows[i]["OrderState"].ToString() == "4")
                    {
                        OrderState = "tbldetails";
                    }
                    string Reserve = ds.Tables[0].Rows[i]["Reserve"].ToString();
                    Reserve = Reserve.Substring(5, 2) + "月" + Reserve.Substring(8, 2) + "日" + Reserve.Substring(11, 2) + "时" + Reserve.Substring(14, 2) + "分";
                    sb.Append("{\"Id\":\"" + ds.Tables[0].Rows[i]["ID"].ToString() + "\",\"OrderState\":\"" + OrderState + "\",\"ContactUser\":\"" + ds.Tables[0].Rows[i]["ContactUser"].ToString() + "\",\"ContactMobile\":\"" + ds.Tables[0].Rows[i]["ContactMobile"].ToString() + "\",");
                    sb.Append("\"Reserve\":\"" + Reserve + "\",\"DineNum\":\"" + ds.Tables[0].Rows[i]["DineNum"].ToString() + "\",\"Category\":\"" + ds.Tables[0].Rows[i]["Category"].ToString() + "\",\"Name\":\"" + ds.Tables[0].Rows[i]["Name"].ToString() + "\"},");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("],");
                sb.Append("\"Msg\":\"\",\"Url\":\"\"");
            }
            else
            {
                sb.Append(",\"Success\":false,\"Msg\":\"没有查询到相关数据！\",\"Url\":\"\"");
            }
            sb.Append("}");
            return sb.ToString();
        }
    }

    /// <summary>
    /// 根据类型获取订单数据
    /// </summary>
    /// <param name="Flag">类型:全部,包间,大厅,加台</param>
    /// <returns>返回Json数据</returns>
    private string getTableType(string Flag)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            DataSet ds = new DataSet();
            StringBuilder sb = new StringBuilder();

            StringBuilder strSql1 = new StringBuilder();
            strSql1.Append("select t.Rooms+t.Hall+t.AddTable Counts,t.Rooms,t.Hall,t.AddTable from ( ");
            strSql1.Append("select sum(case when t.Category='包间' then 1 else 0 end) Rooms,sum(case when t.Category='大厅' then 1 else 0 end) Hall,sum(case when t.Category='加台' then 1 else 0 end) AddTable ");
            strSql1.Append("from H_Hotel_Seat t ");
            strSql1.Append("left join D_Order r ");
            strSql1.Append("on t.HotelId =r.H_Id ");
            strSql1.Append("and t.Id = r.DineTable  ");
            strSql1.Append("and r.OrderState in (2,4) ");
            strSql1.Append("and CONVERT(varchar(10), r.OrderTime, 23) = CONVERT(varchar(10), GETDATE(), 23) ");
            strSql1.Append("where t.HotelId = '" + Session[CookieHelp.SESSION_HotelId] + "') t ");
            ds = DbHelperSQL.Query(strSql1.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append("{\"All\":\"" + ds.Tables[0].Rows[0]["Counts"].ToString() + "\",\"Rooms\":\"" + ds.Tables[0].Rows[0]["Rooms"].ToString() + "\",\"Hall\":\"" + ds.Tables[0].Rows[0]["Hall"].ToString() + "\",\"AddTable\":\"" + ds.Tables[0].Rows[0]["AddTable"].ToString() + "\",\"HotelId\":\"" + Session[CookieHelp.SESSION_HotelId] + "\"");
            }
            else
            {
                sb.Append("{\"All\":\"0\",\"Rooms\":\"0\",\"Hall\":\"0\",\"AddTable\":\"0\",\"HotelId\":\"" + Session[CookieHelp.SESSION_HotelId] + "\"");
            }

            StringBuilder strSql2 = new StringBuilder();
            strSql2.Append("select r.Id OrderId,r.OrderState,r.ContactUser,r.ContactMobile,SUBSTRING(r.ReserveDate,6,6)+r.ReserveTime Reserve,r.DineNum,t.HotelId,t.Id SeatId,t.Category,t.Name,t.Numbers  ");
            strSql2.Append("from H_Hotel_Seat t ");
            strSql2.Append("left join D_Order r ");
            strSql2.Append("on t.HotelId =r.H_Id ");
            strSql2.Append("and t.Id = r.DineTable  ");
            strSql2.Append("and r.OrderState in (2,4) ");
            strSql2.Append("and CONVERT(varchar(10), r.OrderTime, 23) = CONVERT(varchar(10), GETDATE(), 23) ");
            strSql2.Append("where t.HotelId = '" + Session[CookieHelp.SESSION_HotelId] + "' ");
            if (Flag != "" && Flag != "All")
            {
                if (Flag == "Rooms")
                {
                    Flag = "包间";
                }
                else if (Flag == "Hall")
                {
                    Flag = "大厅";
                }
                else if (Flag == "AddTable")
                {
                    Flag = "加台";
                }

                strSql2.Append(" and t.Category='" + Flag + "' ");
            }
            strSql2.Append(" order by r.OrderTime desc ");
            ds = DbHelperSQL.Query(strSql2.ToString());
            string OrderState = string.Empty;
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append(",\"Success\":true,\"Total\":\"" + ds.Tables[0].Rows.Count + "\",");
                sb.Append("\"List\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i]["OrderState"].ToString() == "2")
                    {
                        OrderState = "tbldetail";
                    }
                    else if (ds.Tables[0].Rows[i]["OrderState"].ToString() == "4")
                    {
                        OrderState = "tbldetails";
                    }
                    sb.Append("{\"OrderId\":\"" + ds.Tables[0].Rows[i]["OrderId"].ToString() + "\",\"OrderState\":\"" + OrderState + "\",\"ContactUser\":\"" + ds.Tables[0].Rows[i]["ContactUser"].ToString() + "\",\"ContactMobile\":\"" + ds.Tables[0].Rows[i]["ContactMobile"].ToString() + "\",");
                    sb.Append("\"Reserve\":\"" + ds.Tables[0].Rows[i]["Reserve"].ToString() + "\",\"DineNum\":\"" + ds.Tables[0].Rows[i]["DineNum"].ToString() + "\",\"HotelId\":\"" + ds.Tables[0].Rows[i]["HotelId"].ToString() + "\",\"SeatId\":\"" + ds.Tables[0].Rows[i]["SeatId"].ToString() + "\",");
                    sb.Append("\"Category\":\"" + ds.Tables[0].Rows[i]["Category"].ToString() + "\",\"Name\":\"" + ds.Tables[0].Rows[i]["Name"].ToString() + "\",\"Numbers\":\"" + ds.Tables[0].Rows[i]["Numbers"].ToString() + "\"},");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("],");
                sb.Append("\"Msg\":\"\",\"Url\":\"\"");
            }
            else
            {
                sb.Append(",\"Success\":false,\"Msg\":\"没有查询到相关数据！\",\"Url\":\"\"");
            }
            sb.Append("}");
            return sb.ToString();
        }
    }

    /// <summary>
    /// 根据操作获取订单数据
    /// </summary>
    /// <param name="Flag">操作:就坐,开台,结账</param>
    /// <returns>返回Json数据</returns>
    private string getHandleType(string Flag)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            DataSet ds = new DataSet();
            StringBuilder sb = new StringBuilder();

            StringBuilder strSql1 = new StringBuilder();
       

            strSql1.Append("select sum( case when t.OrderState='4' and s.TableState=1  then 1 else 0 end) Seated, ");
            strSql1.Append("sum(case when t.OrderState='2' then 1 else 0 end )Scheduled, sum(case when  t.OrderId is null and t.Status=0 then 1 else 0 end )OpenTable, sum(case when s.TableState=0 and  t.OrderState='4'  and t.Status=1  then 1 else 0 end )CheckOut, ");
            strSql1.Append("sum(case when  t.Status=1 and (t.OrderId is null or OrderState<>4)  then 1 else 0 end )[Clear] from ( ");
            strSql1.Append("select t.Status, r.Id OrderId,r.OrderState,r.ContactUser,r.ContactMobile,SUBSTRING(r.ReserveDate,6,6)+r.ReserveTime Reserve,r.DineNum,t.HotelId,t.Category,t.Name,t.Numbers ");
            strSql1.Append("from H_Hotel_Seat t ");
            strSql1.Append("left join D_Order r ");
            strSql1.Append("on t.HotelId =r.H_Id ");
            strSql1.Append("and t.Id = r.DineTable ");
            //strSql1.Append("and CONVERT(varchar(10), r.OrderTime, 23) = CONVERT(varchar(10), GETDATE(), 23) ");
            strSql1.Append("and  datediff(HOUR,r.OrderTime,getDate())<=1 and datediff(HOUR,r.OrderTime,getDate()) >=-1   ");
            strSql1.Append("   and r.OrderState  not in (3,5,6,7) ) t  ");
            strSql1.Append("left join (select a.OrderId,case when count(*)*4=sum(b.DishState) then 0 else 1 end TableState from D_Order_Details a,D_CuiCai b where a.Id=b.DishId and a.OrderId=b.OrderId group by a.OrderId) s ");
            strSql1.Append("on t.OrderId=s.OrderId ");
            strSql1.Append("where t.HotelId = '" + Session[CookieHelp.SESSION_HotelId] + "' ");

           

            ds = DbHelperSQL.Query(strSql1.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append("{\"Seated\":\"" + ds.Tables[0].Rows[0]["Seated"].ToString() + "\",\"OpenTable\":\"" + ds.Tables[0].Rows[0]["OpenTable"].ToString() + "\",\"Scheduled\":\"" + ds.Tables[0].Rows[0]["Scheduled"].ToString() + "\",\"Clear\":\"" + ds.Tables[0].Rows[0]["Clear"].ToString() + "\",\"CheckOut\":\"" + ds.Tables[0].Rows[0]["CheckOut"].ToString() + "\",\"HotelId\":\"" + Session[CookieHelp.SESSION_HotelId] + "\"");
            }
            else
            {
                sb.Append("{\"Seated\":\"0\",\"OpenTable\":\"0\",\"CheckOut\":\"0\",\"HotelId\":\"" + Session[CookieHelp.SESSION_HotelId] + "\"");
            }

            StringBuilder strSql2 = new StringBuilder();
            strSql2.Append("select * from ( select case when t.OrderState='4' and s.TableState=1  then 1 else 0 end Seated, ");//--正在点菜
            strSql2.Append("case when t.OrderState='2' then 1 else 0 end  Scheduled, ");// --已被预订
            strSql2.Append("case when t.OrderId is null and t.Status=0 then 1 else 0 end OpenTable, ");// --欢迎光临
            strSql2.Append("case when s.TableState=0 and  t.OrderState='4'  and t.Status=1 then 1 else 0 end CheckOut, ");//--正在用餐
            strSql2.Append("case when   t.Status=1 and (t.OrderId is null or OrderState<>4)   then 1 else 0 end [Clear], ");//--正在清理
            strSql2.Append("case when t.OrderState=7 then '' else t.OrderId end as OrderId,t.OrderState,t.ContactUser,t.ContactMobile,t.Reserve,t.DineNum,t.HotelId,t.SeatId,t.Category,t.Name,t.Numbers,TableState from ( ");
            strSql2.Append("select t.Status, r.Id OrderId,r.OrderState,r.ContactUser,r.ContactMobile,SUBSTRING(r.ReserveDate,6,6)+r.ReserveTime Reserve,r.DineNum,t.HotelId,t.Id SeatId,t.Category,t.Name,t.Numbers ");
            strSql2.Append("from H_Hotel_Seat t ");
            strSql2.Append("left join D_Order r ");
            strSql2.Append("on t.HotelId =r.H_Id ");
            strSql2.Append("and t.Id = r.DineTable ");
            //strSql2.Append("and CONVERT(varchar(10), r.OrderTime, 23) = CONVERT(varchar(10), GETDATE(), 23) ");
            strSql2.Append("and  datediff(HOUR,r.OrderTime,getDate())<=1 and datediff(HOUR,r.OrderTime,getDate()) >=-1   ");
            //strSql2.Append("and r.OrderState in (4)  where  t.Status=0 ) t  ");
            strSql2.Append("  and r.OrderState  not in (3,5,6,7) ) t  ");
            strSql2.Append("left join (select a.OrderId,case when count(*)*4=sum(b.DishState) then 0 else 1 end TableState from D_Order_Details a,D_CuiCai b where a.Id=b.DishId and a.OrderId=b.OrderId group by a.OrderId) s ");
            strSql2.Append("on t.OrderId=s.OrderId ");
            strSql2.Append("where t.HotelId = '" + Session[CookieHelp.SESSION_HotelId] + "' ) abc where 1=1"); 

            if (Flag != "")
            {
                if (Flag == "Seated")
                {
                    strSql2.Append("and Seated = 1 ");
                } 
                if (Flag == "Scheduled")
                {
                  //预定 
                  /*  strSql2=new StringBuilder();
                    strSql2.Append("select * from ( select case when t.OrderState='4' and s.TableState=1  then 1 else 0 end Seated, ");//--正在点菜
                    strSql2.Append("case when t.OrderState='2' then 1 else 0 end  Scheduled, ");// --已被预订
                    strSql2.Append("case when t.OrderId is null or (t.Status=0 and t.OrderState<>2 and t.OrderState<>4) then 1 else 0 end OpenTable, ");// --欢迎光临
                    strSql2.Append("case when s.TableState=0 and  t.OrderState='4'  and t.Status=1 then 1 else 0 end CheckOut, ");//--正在用餐
                    strSql2.Append("case when  s.TableState=0 and t.OrderState in(5,7) and t.Status=1 then 1 else 0 end [Clear], ");//--正在清理
                    strSql2.Append("t.OrderId,t.OrderState,t.ContactUser,t.ContactMobile,t.Reserve,t.DineNum,t.HotelId,t.SeatId,t.Category,t.Name,t.Numbers,TableState from ( ");
                    strSql2.Append("select t.Status, r.Id OrderId,r.OrderState,r.ContactUser,r.ContactMobile,SUBSTRING(r.ReserveDate,6,6)+r.ReserveTime Reserve,r.DineNum,t.HotelId,t.Id SeatId,t.Category,t.Name,t.Numbers ");
                    strSql2.Append("from H_Hotel_Seat t ");
                    strSql2.Append("left join D_Order r ");
                    strSql2.Append("on t.HotelId =r.H_Id ");
                    strSql2.Append("and t.Id = r.DineTable ");
                    strSql2.Append("and CONVERT(varchar(10), r.OrderTime, 23) = CONVERT(varchar(10), GETDATE(), 23) ");
                   // strSql2.Append("and  datediff(HOUR,r.OrderTime,getDate())<=1 and datediff(HOUR,r.OrderTime,getDate()) >=-1   ");
                    //strSql2.Append("and r.OrderState in (4)  where  t.Status=0 ) t  ");
                    strSql2.Append(") t ");
                    strSql2.Append("left join (select a.OrderId,case when count(*)*4=sum(b.DishState) then 0 else 1 end TableState from D_Order_Details a,D_CuiCai b where a.Id=b.DishId and a.OrderId=b.OrderId group by a.OrderId) s ");
                    strSql2.Append("on t.OrderId=s.OrderId ");
                    strSql2.Append("where t.HotelId = '" + Session[CookieHelp.SESSION_HotelId] + "' ) abc where 1=1"); */  
                    strSql2.Append("and Scheduled = 1 ");
                }   
                else if (Flag == "OpenTable")
                {
                    strSql2.Append("and OpenTable = 1 ");
                }
                else if (Flag == "CheckOut")
                {
                    strSql2.Append("and CheckOut  = 1 ");
                }
                else if (Flag == "Clear")
                {
                    strSql2.Append("and Clear = 1 ");
                } 
            }
            ds = DbHelperSQL.Query(strSql2.ToString());
            string OrderState = string.Empty;
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append(",\"Success\":true,\"Total\":\"" + ds.Tables[0].Rows.Count + "\",");
                sb.Append("\"List\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    sb.Append("{\"OrderId\":\"" + ds.Tables[0].Rows[i]["OrderId"].ToString() + "\",\"OrderState\":\"" + ds.Tables[0].Rows[i]["OrderState"].ToString() + "\",\"ContactUser\":\"" + ds.Tables[0].Rows[i]["ContactUser"].ToString() + "\",\"ContactMobile\":\"" + ds.Tables[0].Rows[i]["ContactMobile"].ToString() + "\",");
                    sb.Append("\"Reserve\":\"" + ds.Tables[0].Rows[i]["Reserve"].ToString() + "\",\"DineNum\":\"" + ds.Tables[0].Rows[i]["DineNum"].ToString() + "\",\"HotelId\":\"" + ds.Tables[0].Rows[i]["HotelId"].ToString() + "\",\"SeatId\":\"" + ds.Tables[0].Rows[i]["SeatId"].ToString() + "\",");

                    sb.Append("\"Seated\":\"" + ds.Tables[0].Rows[i]["Seated"].ToString() + "\",\"OpenTable\":\"" + ds.Tables[0].Rows[i]["OpenTable"].ToString() + "\",\"CheckOut\":\"" + ds.Tables[0].Rows[i]["CheckOut"].ToString() + "\",\"Clear\":\"" + ds.Tables[0].Rows[i]["Clear"].ToString() + "\",\"Scheduled\":\"" + ds.Tables[0].Rows[i]["Scheduled"].ToString() + "\","); 

                    sb.Append("\"Category\":\"" + ds.Tables[0].Rows[i]["Category"].ToString() + "\",\"Name\":\"" + ds.Tables[0].Rows[i]["Name"].ToString() + "\",\"Numbers\":\"" + ds.Tables[0].Rows[i]["Numbers"].ToString() + "\",\"TableState\":\"" + ds.Tables[0].Rows[i]["TableState"].ToString() + "\"},");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("],");
                sb.Append("\"Msg\":\"\",\"Url\":\"\"");
            }
            else
            {
                sb.Append(",\"Success\":false,\"Msg\":\"没有查询到相关数据！\",\"Url\":\"\"");
            }
            sb.Append("}");
            return sb.ToString();
        }
    }

    /// <summary>
    /// 开台
    /// </summary>
    /// <param name="HotelId">酒店ID</param>
    /// <param name="HotelName">酒店名称</param>
    /// <param name="DineTableId">餐桌ID</param>
    /// <param name="Category">餐桌类型</param>
    /// <param name="jcrs">就餐人数</param>
    /// <returns>返回Json数据</returns>
    private string openDineTable(string HotelId, string HotelName, string DineTableId, string Category, string jcrs)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            StringBuilder sb = new StringBuilder();
            //判断座位是否清桌 
            string strtemp = "select Status from H_Hotel_Seat where Id=" + DineTableId;
            DataSet dstemp = DbHelperSQL.Query(strtemp);
            if (dstemp.Tables[0].Rows.Count > 0)
            {
                var dineStatus = Convert.ToInt32(dstemp.Tables[0].Rows[0]["Status"].ToString());
                if (dineStatus == 1)
                {
                    sb.Append("{\"Success\":false,\"Msg\":\"当前桌位还未清桌，请先清桌！\",\"Url\":\"\",\"OrderId\":\"\",\"BookedDate\":\"\"}");
                    return sb.ToString();
                }  
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\",\"OrderId\":\"\",\"BookedDate\":\"\"}");
                return sb.ToString();
            }
            
            var list = new List<string>(); 
            int OrderId = 0;
            string strSql = "select MAX(Id)+1 OrderId,SUBSTRING(CONVERT(varchar(50), GETDATE(), 20),0,17) BookedDate,CONVERT(varchar(4), GETDATE(), 112)+'年'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112),5,2)+'月'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112),7,8)+'日' ReserveDate,CONVERT(varchar(2), GETDATE(), 8)+'时'+SUBSTRING(CONVERT(varchar(5), GETDATE(), 8),4,2)+'分' ReserveTime from D_Order";
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (string.IsNullOrEmpty(ds.Tables[0].Rows[0]["OrderId"].ToString()))
                {
                    OrderId++;
                }
                else
                {
                    OrderId = Convert.ToInt32(ds.Tables[0].Rows[0]["OrderId"].ToString());
                }



                list.Add("set IDENTITY_INSERT D_Order on  insert into D_Order(Id,OrderState,OrderTime,OrderChannel,ContactUser,ReserveDate,ReserveTime,H_Id,HotelName,DineTable,Dinecondition,U_Id,CreateTime,CreateUser,dinenum) "
                        + "values('" + OrderId + "','4',GETDATE(),'店面','到店食客','" + ds.Tables[0].Rows[0]["ReserveDate"].ToString() + "','" + ds.Tables[0].Rows[0]["ReserveTime"].ToString() + "','" + HotelId + "','" + HotelName + "','" + DineTableId + "','" + Category + "','-1',GETDATE(),'" + Session[CookieHelp.SESSION_H_UID].ToString() + "','" + jcrs + "');");
                list.Add("update H_Hotel_Seat set Status='1' where Id='" + DineTableId + "' and HotelId='" + HotelId + "';");

                int rows = DbHelperSQL.ExecuteSqlTran(list);
                if (rows > 0)
                {
                    sb.Append("{\"Success\":true,\"Msg\":\"操作成功！\",\"Url\":\"opentable.html\",\"OrderId\":\"" + OrderId + "\",\"BookedDate\":\"" + ds.Tables[0].Rows[0]["BookedDate"].ToString() + "\"}");
                }
                else
                {
                    sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\",\"OrderId\":\"\",\"BookedDate\":\"\"}");
                }
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\",\"OrderId\":\"\",\"BookedDate\":\"\"}");
            }

            return sb.ToString();
        }
    }

    /// <summary>
    /// 获取酒店菜谱分类
    /// </summary>
    /// <param name="HotelId">酒店ID</param>
    /// <returns>返回Json数据</returns>
    private string getCookbookCategory()
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            //lyz 2015-05-04 添加菜谱排序
            DataSet ds = DbHelperSQL.Query("select Id,Name,Code from H_Hotel_CookbookCategory where HotelId='" + Session[CookieHelp.SESSION_HotelId] + "' order by code asc ");
            StringBuilder sb = new StringBuilder();
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append("{\"Success\":true,");
                sb.Append("\"List\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    sb.Append("{\"Id\":\"" + ds.Tables[0].Rows[i]["Id"].ToString() + "\",\"Name\":\"" + ds.Tables[0].Rows[i]["Name"].ToString() + "\",\"Code\":\"" + ds.Tables[0].Rows[i]["Code"].ToString() + "\"},");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("]");
                sb.Append("}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"没有查询到本酒店菜谱信息！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        } 
    }

    /// <summary>
    /// 获取酒店菜谱菜单
    /// </summary>
    /// <param name="Flag">菜谱类型</param>
    /// <returns>返回Json数据</returns>
    private string getCookbookList(string Flag)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            string sqlStr = string.Empty;
            if (string.IsNullOrEmpty(Flag))
            {
                sqlStr = "select y.Id CategoryId, case StartIdentification when  0 then 1 else y.IsDisplay END as IsDisplay ,k.Id,k.Name,k.discount as Price,k.Unit,k.EstimateClear from H_Hotel_CookbookCategory y,H_Hotel_Cookbook k where y.Id=k.CategoryId and y.HotelId='" + Session[CookieHelp.SESSION_HotelId] + "' and k.EstimateClear<>'0'";
            }
            else
            {
                sqlStr = "select y.Id CategoryId,case StartIdentification when  0 then 1 else y.IsDisplay END as IsDisplay,k.Id,k.Name,k.discount as Price,k.Unit,k.EstimateClear from H_Hotel_CookbookCategory y,H_Hotel_Cookbook k where y.Id=k.CategoryId and y.HotelId='" + Session[CookieHelp.SESSION_HotelId] + "' and CategoryId='" + Flag + "' and k.EstimateClear<>'0' ";
            }
            DataSet ds = DbHelperSQL.Query(sqlStr);
            StringBuilder sb = new StringBuilder();
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append("{\"Success\":true,");
                sb.Append("\"List\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    sb.Append("{\"CategoryId\":\"" + ds.Tables[0].Rows[i]["CategoryId"].ToString() + "\",\"IsDisplay\":\"" + ds.Tables[0].Rows[i]["IsDisplay"].ToString() + "\",\"Id\":\"" + ds.Tables[0].Rows[i]["Id"].ToString() + "\",\"Name\":\"" + ds.Tables[0].Rows[i]["Name"].ToString() + "\",\"Price\":\"" + ds.Tables[0].Rows[i]["Price"].ToString() + "\",\"Unit\":\"" + ds.Tables[0].Rows[i]["Unit"].ToString() + "\",\"EstimateClear\":\"" + ds.Tables[0].Rows[i]["EstimateClear"].ToString() + "\"},");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("]");
                sb.Append("}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"没有查询到此菜谱菜单信息！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 点菜,加菜
    /// </summary>
    /// <param name="HotelId">酒店ID</param>
    /// <param name="Flag">所选菜品</param>
    /// <param name="U_Id">用户ID</param>
    /// <returns>返回Json数据</returns>
    private string updateOrderCookBook(string OrderId, string array, string U_Id, string StateFlag)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            List<String> list = new List<string>();
            StringBuilder sb = new StringBuilder();

            int Num = 0;
            string CategoryId = string.Empty;
            string CookbookId = string.Empty;
            string IsDisplay = string.Empty;
            string State = string.Empty;

            for (int i = 0; i < array.Split('|').Length; i++)
            {
                Num = Convert.ToInt32(array.Split('|')[i].Split(',')[1]);
                for (int j = 0; j < Num; j++)
                {
                    CategoryId = array.Split('|')[i].Split(',')[0].Split('_')[1];
                    CookbookId = array.Split('|')[i].Split(',')[0].Split('_')[2];
                    IsDisplay = array.Split('|')[i].Split(',')[0].Split('_')[3];
                    //即时消费品
                    if (IsDisplay == "1" && StateFlag == "10")
                    {
                        State = "3";
                    }
                    else
                    {
                        State = StateFlag;
                    }
                    list.Add("insert into D_Order_Details(OrderId,HCid,CName,Num,Price,DisAmount,IsGuest,UId,State)"
                            + "select '" + OrderId + "',Id,Name,1,Price,0.00,0,'" + U_Id + "'," + State + " from H_Hotel_Cookbook where Id='" + CookbookId + "' and CategoryId='" + CategoryId + "';");
                }
            }
            if (IsDisplay == "1")
            {
                list.Add("insert into D_CuiCai(DishId,DishName,DishState,OrderId,DineTable,CookChef,OrderConfirmTime,CookWeight,TimeWeight,PressWeight,OtherWeight) select s.Id,s.CName,s.State,r.Id,r.DineTable,'" + Session[CookieHelp.SESSION_H_UserName] + "',getdate(),k.CookingWeights,0,0,0 from D_Order r,D_Order_Details s,H_Hotel_Cookbook k where r.Id = s.OrderId and s.HCId=k.Id and r.Id ='" + OrderId + "' and s.Id not in (select DishId from D_CuiCai where OrderId='" + OrderId + "');");
            }
            else
            {
                list.Add("insert into D_CuiCai(DishId,DishName,DishState,OrderId,DineTable,CookWeight,TimeWeight,PressWeight,OtherWeight) select s.Id,s.CName,s.State,r.Id,r.DineTable,k.CookingWeights,0,0,0 from D_Order r,D_Order_Details s,H_Hotel_Cookbook k where r.Id = s.OrderId and s.HCId=k.Id and r.Id ='" + OrderId + "' and s.Id not in (select DishId from D_CuiCai where OrderId='" + OrderId + "');");
            }
            int rows = DbHelperSQL.ExecuteSqlTran(list);
            if (rows > 0)
            {
                sb.Append("{\"Success\":true,\"Msg\":\"操作成功！\",\"Url\":\"tbldetails.html\"}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\"}");
            }

            return sb.ToString();
        }
    }

    /// <summary>
    /// 取消此台
    /// </summary>
    /// <param name="OrderId">订单ID</param>
    /// <returns>返回Json数据</returns>
    private string cancelDineTable(string HotelId, string OrderId)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            List<String> list = new List<string>();
            StringBuilder sb = new StringBuilder();
            list.Add("update D_Order set OrderState='3' where Id='" + OrderId + "';");
            list.Add("delete from D_Order_Details where OrderId='" + OrderId + "';");
            list.Add("delete from D_CuiCai where OrderId='" + OrderId + "';");
            list.Add("update H_Hotel_Seat set Status='0' where HotelId='" + HotelId + "' and Id=(select DineTable from D_Order where Id='" + OrderId + "');");

            int rows = DbHelperSQL.ExecuteSqlTran(list);
            if (rows > 0)
            {
                sb.Append("{\"Success\":true,\"Msg\":\"操作成功！\",\"Url\":\"manager.html\"}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\"}");
            }

            return sb.ToString();
        }
    }

    /// <summary>
    /// 获取未就坐订单和订单菜单信息
    /// </summary>
    /// <param name="OrderId">订单号</param>
    /// <returns>返回Json数据</returns>
    private string getOrderDetail(string OrderId)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select t.Id,t.ContactUser,t.Name,t.Numbers,t.ContactMobile,t.DineNum,t.DineTable,t.BookedDate,t.RetentionTime,t.CName,t.Num,t.Price, ");
            strSql.Append("case when GETDATE()>DATEADD(MI,-30,cast(t.BookedDate as datetime)) then 1 else 0 end IsShow from ( ");
            strSql.Append("select r.Id,r.ContactUser,t.Name,t.Numbers,r.ContactMobile,r.DineNum,r.DineTable,SUBSTRING(CONVERT(varchar(20), r.OrderTime, 20),0,17) BookedDate,isnull(g.RetentionTime,'30') RetentionTime,s.CName,sum(Num) as Num,sum(Num)* s.DisAmount as Price ");
            strSql.Append("from D_Order r ");
            strSql.Append("left join D_Order_Details s ");
            strSql.Append("on r.Id = s.OrderId ");
            strSql.Append("and r.U_Id = s.UId ");
            //strSql.Append("and s.State = 0 ");
            strSql.Append("left join H_Hotel_Setting g ");
            strSql.Append("on r.H_Id = g.HotelId ");
            strSql.Append("and r.DineTable = g.Id ");
            strSql.Append("left join H_Hotel_Seat t ");
            strSql.Append("on r.H_Id = t.HotelId ");
            strSql.Append("and r.DineTable = t.Id ");
            strSql.Append("group by r.ID,r.ContactUser,t.Name,t.Numbers,r.ContactMobile,r.DineNum,r.DineTable,r.OrderTime,g.RetentionTime,s.CName,s.Num,s.DisAmount) t ");
            strSql.Append("where t.Id = '" + OrderId + "' ");

            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            StringBuilder sb = new StringBuilder();
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append("{\"Success\":true,");
                sb.Append("\"Id\":\"" + ds.Tables[0].Rows[0]["Id"].ToString() + "\",\"ContactUser\":\"" + ds.Tables[0].Rows[0]["ContactUser"].ToString() + "\",\"Name\":\"" + ds.Tables[0].Rows[0]["Name"].ToString() + "\",\"PeopleNum\":\"" + ds.Tables[0].Rows[0]["Numbers"].ToString() + "\",\"ContactMobile\":\"" + ds.Tables[0].Rows[0]["ContactMobile"].ToString() + "\",");
                sb.Append("\"DineNum\":\"" + ds.Tables[0].Rows[0]["DineNum"].ToString() + "\",\"DineTable\":\"" + ds.Tables[0].Rows[0]["DineTable"].ToString() + "\",\"BookedDate\":\"" + ds.Tables[0].Rows[0]["BookedDate"].ToString() + "\",\"RetentionTime\":\"" + ds.Tables[0].Rows[0]["RetentionTime"].ToString() + "\",");
                string Numbers = string.IsNullOrEmpty(ds.Tables[0].Compute("sum(Num)", "true").ToString()) ? "0" : ds.Tables[0].Compute("sum(Num)", "true").ToString();
               
                string Prices = string.IsNullOrEmpty(ds.Tables[0].Compute("sum(Price)", "true").ToString()) ? "0" : ds.Tables[0].Compute("sum(Price)", "true").ToString();
                sb.Append("\"Numbers\":\"" + Numbers + "\",\"Prices\":\"" + Prices + "\",\"IsShow\":\"" + ds.Tables[0].Rows[0]["IsShow"].ToString() + "\",");
                sb.Append("\"List\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    sb.Append("{\"CName\":\"" + ds.Tables[0].Rows[i]["CName"].ToString() + "\",\"Price\":\"" + ds.Tables[0].Rows[i]["Price"].ToString() + "\",\"Num\":\"" + ds.Tables[0].Rows[i]["Num"].ToString() + "\"},");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("]");
                if (Numbers == "0")
                {
                    sb.Append(",\"Msg\":\"没有查询到本订单菜单信息！\",\"Url\":\"\"");
                }
                sb.Append("}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"没有查询到本订单信息！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 订单就坐
    /// </summary>
    /// <param name="HotelId">酒店ID</param>
    /// <param name="OrderId">订单号</param>
    /// <returns>返回Json数据</returns>
    private string updateOrderState(string HotelId, string OrderId, string jcrs)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            List<String> list = new List<string>();
            list.Add("update D_Order set OrderState = 4,CreateTime =getdate(),DineNum=" + jcrs + " where H_Id='" + HotelId + "' and Id='" + OrderId + "';");
            list.Add("insert into D_CuiCai(DishId,DishName,DishState,OrderId,DineTable,CookWeight,TimeWeight,PressWeight,OtherWeight) select s.Id,s.CName,s.State,r.Id,r.DineTable,k.CookingWeights,0,0,0 from D_Order r,D_Order_Details s,H_Hotel_Cookbook k where r.Id = s.OrderId and s.HCId=k.Id and r.H_Id='" + HotelId + "' and r.Id ='" + OrderId + "';");

            StringBuilder sb = new StringBuilder();
            int rows = DbHelperSQL.ExecuteSqlTran(list);
            if (rows > 0)
            {
                sb.Append("{\"Success\":true,\"Msg\":\"操作成功！\",\"Url\":\"tbldetails.html\"}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 订单延时
    /// </summary>
    /// <param name="OrderId">订单号</param>
    /// <param name="BookedDate">预定日期</param>
    /// <param name="RetentionTime">保留分钟</param>
    /// <returns>返回Json数据</returns>
    private string updateOrderBookedDate(string OrderId, string BookedDate, string RetentionTime)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update D_Order set OrderTime=DATEADD(MI," + RetentionTime + ",OrderTime) where Id='" + OrderId + "'");

            StringBuilder sb = new StringBuilder();
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                sb.Append("{\"Success\":true,\"Msg\":\"操作成功！\",\"Url\":\"\"}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 获取已就坐订单和订单菜单信息
    /// </summary>
    /// <param name="OrderId">订单号</param>
    /// <returns>返回Json数据</returns>
    private string getOrderDetails(string OrderId)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            #region 原口径
            //StringBuilder strSql = new StringBuilder();
            //strSql.Append("select r.Id,r.U_Id,r.ContactUser,t.Name,t.Numbers,r.ContactMobile,r.DineTable,CONVERT(varchar(16),r.CreateTime,20) CreateTime,s.Id as DetailId,");
            //strSql.Append("s.CName,s.Num,case when s.Num > 1 then '('+CONVERT(varchar(2),s.Num)+'份)' else null end Copies, s.Num * s.Price as Price,s.DishState as State,");
            //strSql.Append("case when s.DishState=1 then '请确认' when s.DishState=10 then '等待中' when s.DishState=2 then '炒菜中' when s.DishState=3 then '待上菜' when s.DishState=4 then '已上菜' end StateName ");
            //strSql.Append("from D_Order r ");
            //strSql.Append("left join (select a.*,b.DishState from D_Order_Details a,D_CuiCai b where a.Id=b.DishId and a.OrderId=b.OrderId) s ");
            //strSql.Append("on r.Id = s.OrderId ");
            //strSql.Append("and r.U_Id = s.UId ");
            //strSql.Append("left join H_Hotel_Seat t ");
            //strSql.Append("on r.H_Id = t.HotelId ");
            //strSql.Append("and r.DineTable = t.Id ");
            //strSql.Append("where r.Id = '" + OrderId + "' ");
            //strSql.Append("group by r.Id,r.U_Id,r.ContactUser,t.Name,t.Numbers,r.ContactMobile,r.DineTable,r.CreateTime,s.Id,s.CName,s.Num,s.Price,s.DishState ");
            #endregion

           /* string strSql = @"select d.Id,
                             d.U_Id,
                             d.ContactUser,
                             (select Name from H_Hotel_Seat where HotelId=d.H_Id and Id=d.DineTable) as DineName,
                             (select Numbers from H_Hotel_Seat where HotelId=d.H_Id and Id=d.DineTable) as Numbers,
                             d.ContactMobile,
                             d.DineTable,
                             CONVERT(varchar(16),d.CreateTime,20) CreateTime,
                             t.DishId,
                             t.DishName,
                             sum(t.Num) as Num,
                             sum(t.Weight) Weight,
                             case when t.Unit='斤' then (case when sum(t.Weight)<>'0.00' then '('+CONVERT(varchar(10),sum(t.Weight))+t.Unit+')' else null end)
                             else (case when sum(t.Num) > 1 then '('+CONVERT(varchar(2),sum(t.Num))+t.Unit+')' else null end) end Copies,
                             SUM(t.Price) as Price,
                             t.Unit,
                             t.DishState,
                             case when t.IsDisplay=0 then 
                             (case when t.DishState=1 then '请确认' when t.DishState=10 then '等待中' when t.DishState=2 then '炒菜中' when t.DishState=3 then '待上菜' when t.DishState=4 then '已上菜' end)
                             else (case when t.DishState=1 then '请确认' when t.DishState=10 or t.DishState=3 then '请等待' when t.DishState=4 then '已上' end) end StateName,
                             t.IsDisplay
                             from D_Order d 
                             Join (
	                            select i.OrderId,i.DishState,i.DishName,sum(s.Num) Num,'0.00' Weight,s.Price,k.Unit,y.IsDisplay,DishId = stuff((select '|' + CONVERT(varchar(100),DishId) from D_CuiCai t 
	                            where OrderId = i.OrderId and DishName=i.DishName for xml path('')) , 1 , 1 , '') 
	                            from D_CuiCai i,D_Order_Details s,H_Hotel_Cookbook k,H_Hotel_CookbookCategory y 
	                            where i.DishId=s.Id and i.OrderId=s.OrderId and s.HCId=k.Id and k.CategoryId=y.Id and k.Unit<>'斤'
	                            group by i.OrderId,i.DishState,i.DishName,s.Num,s.Price,k.Unit,y.IsDisplay 
	                            union all
	                            select i.OrderId,i.DishState,i.DishName,sum(s.Num) Num,sum(s.Weight) Weight,s.Price,k.Unit,y.IsDisplay,CONVERT(varchar(100),DishId) DishId
	                            from D_CuiCai i,D_Order_Details s,H_Hotel_Cookbook k,H_Hotel_CookbookCategory y 
	                            where i.DishId=s.Id and i.OrderId=s.OrderId and s.HCId=k.Id and k.CategoryId=y.Id and k.Unit='斤'
	                            group by i.OrderId,i.DishState,i.DishName,s.Num,s.Price,k.Unit,y.IsDisplay,DishId 
                             ) t on t.OrderId=d.Id 
                            where d.Id='" + OrderId + @"'
                            group by d.H_Id,d.Id,d.U_Id,d.ContactUser,d.ContactMobile,d.DineTable,CONVERT(varchar(16),d.CreateTime,20),d.Dinecondition,t.DishName,t.Unit,t.DishState,t.IsDisplay,t.DishId ";*/


            string strSql = @"select d.H_Id,d.Id,
                             d.U_Id,
                             d.ContactUser,
                             (select Name from H_Hotel_Seat where HotelId=d.H_Id and Id=d.DineTable) as DineName,
                             (select Numbers from H_Hotel_Seat where HotelId=d.H_Id and Id=d.DineTable) as Numbers,
                             d.ContactMobile,
                             d.DineTable,
                             CONVERT(varchar(16),d.CreateTime,20) CreateTime,
                             t.DishId,
                             t.DishName,
                             sum(t.Num) as Num,
                             sum(t.Weight) Weight,
                             case when t.Unit='斤' then (case when sum(t.Weight)<>'0.00' then '('+CONVERT(varchar(10),sum(t.Weight))+t.Unit+')' else null end)
                             else (case when sum(t.Num) > 1 then '('+CONVERT(varchar(2),sum(t.Num))+t.Unit+')' else null end) end Copies,
                             cast(sum(t.Price)*sum(t.Num)*sum(t.Weights) as decimal(10,2)) as Price,
                             t.Unit,
                             t.DishState,
                             case when t.IsDisplay=0 then 
                             (case when t.DishState=1 then '请确认' when t.DishState=10 then '等待' when t.DishState=2 then '炒菜中' when t.DishState=3 then '等待' when t.DishState=4 then '已上' end)
                             else (case when t.DishState=1 then '请确认' when t.DishState=10 or t.DishState=3 then '等待' when t.DishState=4 then '已上' end) end StateName,
                             t.IsDisplay
                             from D_Order d 
                             Left Join (
	                            select i.OrderId,i.DishState,i.DishName,sum(s.Num) Num,'0.00' Weight,'1' Weights,k.Discount as Price,k.Unit,case StartIdentification when  0 then 1 else y.IsDisplay end  as IsDisplay,DishId = stuff((select '|' + CONVERT(varchar(100),DishId) from D_CuiCai t 
	                            where OrderId = i.OrderId and DishName=i.DishName for xml path('')) , 1 , 1 , '') 
	                            from D_CuiCai i,D_Order_Details s,H_Hotel_Cookbook k,H_Hotel_CookbookCategory y 
	                            where i.DishId=s.Id and i.OrderId=s.OrderId and s.HCId=k.Id and k.CategoryId=y.Id and k.Unit<>'斤'
	                            group by i.OrderId,i.DishState,i.DishName,s.Num,k.Discount,k.Unit,y.IsDisplay,StartIdentification
	                            union all
	                            select i.OrderId,i.DishState,i.DishName,sum(s.Num) Num,sum(s.Weight) Weight,case when sum(s.Weight)=0.00 then 1 else sum(s.Weight) end Weights,s.Price,k.Unit,y.IsDisplay,CONVERT(varchar(100),DishId) DishId
	                            from D_CuiCai i,D_Order_Details s,H_Hotel_Cookbook k,H_Hotel_CookbookCategory y 
	                            where i.DishId=s.Id and i.OrderId=s.OrderId and s.HCId=k.Id and k.CategoryId=y.Id and k.Unit='斤'
	                            group by i.OrderId,i.DishState,i.DishName,s.Num,s.Price,k.Unit,y.IsDisplay,DishId 
                             ) t on t.OrderId=d.Id 
                            where d.Id='" + OrderId + @"'
                            group by d.H_Id,d.Id,d.U_Id,d.ContactUser,d.ContactMobile,d.DineTable,CONVERT(varchar(16),d.CreateTime,20),d.Dinecondition,t.DishName,t.Unit,t.DishState,t.IsDisplay,t.DishId ";
             
            DataSet ds = DbHelperSQL.Query(strSql);
            StringBuilder sb = new StringBuilder();
            if (ds.Tables[0].Rows.Count > 0)
            {
                string TableState = string.Empty;
                string sql = "select case when count(*)*4=sum(b.DishState) then 0 else 1 end TableState from D_Order_Details a,D_CuiCai b where a.Id=b.DishId and a.OrderId=b.OrderId and a.OrderId='" + OrderId + "' group by b.DishState";
                DataSet dt = DbHelperSQL.Query(sql);
                if (dt.Tables[0].Rows.Count > 0)
                {
                    TableState = dt.Tables[0].Rows[0]["TableState"].ToString();
                }

                sb.Append("{\"Success\":true,");
                sb.Append("\"H_Id\":\"" + ds.Tables[0].Rows[0]["H_Id"].ToString() + "\",\"Id\":\"" + ds.Tables[0].Rows[0]["Id"].ToString() + "\",\"U_Id\":\"" + ds.Tables[0].Rows[0]["U_Id"].ToString() + "\",\"ContactUser\":\"" + ds.Tables[0].Rows[0]["ContactUser"].ToString() + "\",\"DineName\":\"" + ds.Tables[0].Rows[0]["DineName"].ToString() + "\",");
                sb.Append("\"PeopleNum\":\"" + ds.Tables[0].Rows[0]["Numbers"].ToString() + "\",\"ContactMobile\":\"" + ds.Tables[0].Rows[0]["ContactMobile"].ToString() + "\",\"DineTable\":\"" + ds.Tables[0].Rows[0]["DineTable"].ToString() + "\",\"LastModifyDate\":\"" + ds.Tables[0].Rows[0]["CreateTime"].ToString() + "\",");
                string Numbers = string.IsNullOrEmpty(ds.Tables[0].Compute("sum(Num)", "true").ToString()) ? "0" : ds.Tables[0].Compute("sum(Num)", "true").ToString();
                string Prices = string.IsNullOrEmpty(ds.Tables[0].Compute("sum(Price)", "true").ToString()) ? "0" : ds.Tables[0].Compute("sum(Price)", "true").ToString();
                sb.Append("\"TableState\":\"" + TableState + "\",\"Numbers\":\"" + Numbers + "\",\"Prices\":\"" + Prices + "\",");
                sb.Append("\"List\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    sb.Append("{\"DishId\":\"" + ds.Tables[0].Rows[i]["DishId"].ToString() + "\",\"DishName\":\"" + ds.Tables[0].Rows[i]["DishName"].ToString() + "\",\"Price\":\"" + ds.Tables[0].Rows[i]["Price"].ToString() + "\",\"Num\":\"" + ds.Tables[0].Rows[i]["Num"].ToString() + "\",\"Weight\":\"" + ds.Tables[0].Rows[i]["Weight"].ToString() + "\",\"Copies\":\"" + ds.Tables[0].Rows[i]["Copies"].ToString() + "\",");
                    sb.Append("\"Unit\":\"" + ds.Tables[0].Rows[i]["Unit"].ToString() + "\",\"DishState\":\"" + ds.Tables[0].Rows[i]["DishState"].ToString() + "\",\"StateName\":\"" + ds.Tables[0].Rows[i]["StateName"].ToString() + "\",\"IsDisplay\":\"" + ds.Tables[0].Rows[i]["IsDisplay"].ToString() + "\"},");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("]");
                if (Numbers == "0")
                {
                    sb.Append(",\"Msg\":\"没有查询到本订单菜单信息！\",\"Url\":\"manager.html\"");
                }
                sb.Append("}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"没有查询到本订单信息！\",\"Url\":\"manager.html\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 催菜
    /// </summary>
    /// <param name="OrderId">订单ID</param>
    /// <param name="DishId">菜品ID</param>
    /// <returns>返回Json数据</returns>
    private string updateCookWeight(string OrderId, string DishId, string DishState)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            int CookWeight = 0;
            //部长每催促一次，优先等级上升5；服务员每催促一次，优先等级上升1；
            if (Session[CookieHelp.SESSION_RoleId].ToString() == "1" || Session[CookieHelp.SESSION_RoleId].ToString() == "2")
            {
                CookWeight = 5;
            }
            else
            {
                CookWeight = 1;
            }

            List<String> list = new List<string>();

            for (int i = 0; i < DishId.Split('|').Length; i++)
            {
                list.Add("update D_CuiCai set CookWeight = CookWeight + " + CookWeight + ",TimeWeight = datediff(minute,OrderConfirmTime,getdate()) where OrderId='" + OrderId + "' and DishId='" + DishId.Split('|')[i] + "';");
            }

            StringBuilder sb = new StringBuilder();
            int rows = DbHelperSQL.ExecuteSqlTran(list);
            if (rows > 0)
            {
                sb.Append("{\"Success\":true,\"Msg\":\"操作成功！\",\"Url\":\"\"}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 取消菜单菜品
    /// </summary>
    /// <param name="OrderId">订单ID</param>
    /// <param name="DishId">菜品ID</param>
    /// <returns>返回Json数据</returns>
    private string cancelCookbook(string OrderId, string DishId, string Num, string IsDisplay)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            List<String> list = new List<string>();

            for (int i = 0; i < DishId.Split('|').Length; i++)
            {
                if (IsDisplay == "1")
                {
                    list.Add("delete from D_Order_Details where Id='" + DishId.Split('|')[i] + "' and OrderId='" + OrderId + "' and State in ('1','3');");
                    list.Add("delete from D_CuiCai where DishId='" + DishId.Split('|')[i] + "' and OrderId='" + OrderId + "' and DishState in ('1','3');");
                }
                else
                {
                    list.Add("delete from D_Order_Details where Id='" + DishId.Split('|')[i] + "' and OrderId='" + OrderId + "' and State in ('1','3','10');");
                    list.Add("delete from D_CuiCai where DishId='" + DishId.Split('|')[i] + "' and OrderId='" + OrderId + "' and DishState in ('1','3','10');");
                }  
            }

            StringBuilder sb = new StringBuilder();
            int rows = DbHelperSQL.ExecuteSqlTran(list);
            if (rows > 0)
            { 
                //string sqlroder = "select count(1) from D_Order_Details where OrderId=" + OrderId;
                //bool iscount =DbHelperSQL.Exists(sqlroder);
                //if (!iscount)
                //{
                //    string updateOrderStatus = "Update D_Order set OrderState=3 where Id=" + OrderId;
                //    DbHelperSQL.ExecuteSql(updateOrderStatus); 
                //}  
                sb.Append("{\"Success\":true,\"Msg\":\"操作成功！\",\"Url\":\"\"}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 获取酒店待烹饪数据
    /// </summary>
    /// <param name="Flag">数据类别:所有,加急,普通</param>
    /// <returns>返回Json数据</returns>
    private string getCookList(string Flag)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            string H_UserName = Session[CookieHelp.SESSION_H_UserName].ToString();
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select d.Id as OrderId,
                             t.DishId,
                             t.DishName,
                             sum(t.Num) as Num,
                             SUM(t.Price) as Price,
                             case when t.Unit='斤' then (case when sum(t.Weight)<>'0.00' then '('+CONVERT(varchar(10),sum(t.Weight))+t.Unit+')' else null end)
                             else (case when sum(t.Num) > 1 then '('+CONVERT(varchar(2),sum(t.Num))+t.Unit+')' else null end) end Copies,
                             case when t.CookChef='"+ H_UserName + @"' then 1 else 0 end Flag,
                             t.CookChef,
                             t.CookbookId,
                             t.CookingNumber,
                             t.DishState
                             from D_Order d 
                             Join (
	                            select i.OrderId,i.DishState,i.DishName,sum(s.Num) Num,sum(s.Weight) Weight,sum(s.Price) Price,k.Unit,
	                            i.CookChef,y.RoleId,k.Id as CookbookId,k.CookingNumber,
	                            max((i.CookWeight+i.PressWeight+DATEDIFF(minute,i.Createtime,getdate()))) CookWeight,
	                            DishID = (case when k.Unit<>'斤' and i.DishState='2' then stuff((select '|' + CONVERT(varchar(100),DishId) from D_CuiCai t 
	                            where OrderId = i.OrderId and DishName=i.DishName for xml path('')) , 1 , 1 , '') else CONVERT(varchar(100),DishId) end)
	                            from D_CuiCai i,D_Order_Details s,H_Hotel_Cookbook k,H_Hotel_CookbookCategory y 
	                            where i.DishId=s.Id and i.OrderId=s.OrderId and s.HCId=k.Id and k.CategoryId=y.Id and y.IsDisplay='0'
	                            and (case when k.Unit='斤' and s.Weight='0.00' then 0 else 1 end)=1
	                            group by i.DishID,i.OrderId,i.DishState,i.DishName,k.Unit,i.CookChef,y.RoleId,k.Id,k.CookingNumber 
                             ) t on t.OrderId=d.Id 
                            where t.DishState in (2,10) and d.H_Id = '" + Session[CookieHelp.SESSION_HotelId] + "' ");
            //根据用户部门角色获取不同菜品数据
            if (!string.IsNullOrEmpty(Session[CookieHelp.SESSION_DeptId].ToString()))
            {
                strSql.Append("and t.RoleId = '" + Session[CookieHelp.SESSION_DeptId].ToString() + "' ");
            }

            if (Flag == "Urgent")
            {
                strSql.Append("and t.DishState = 10 ");
            }
            else if (Flag == "General")
            {
                strSql.Append("and t.DishState = 2 ");
            }
            strSql.Append("group by d.Id,t.DishId,t.DishName,t.Unit,t.DishState,t.CookChef,t.RoleId,t.CookbookId,t.CookingNumber,t.CookWeight,t.Price ");
            strSql.Append("order by t.CookWeight desc,t.Price desc");

            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            StringBuilder sb = new StringBuilder();
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append("{\"Success\":true,\"Total\":\"" + ds.Tables[0].Rows.Count + "\",");
                sb.Append("\"List\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    sb.Append("{\"OrderId\":\"" + ds.Tables[0].Rows[i]["OrderId"].ToString() + "\",\"DishId\":\"" + ds.Tables[0].Rows[i]["DishId"].ToString() + "\",\"DishName\":\"" + ds.Tables[0].Rows[i]["DishName"].ToString() + "\",\"Copies\":\"" + ds.Tables[0].Rows[i]["Copies"].ToString() + "\",");
                    sb.Append("\"CookChef\":\"" + ds.Tables[0].Rows[i]["CookChef"].ToString() + "\",\"CookbookId\":\"" + ds.Tables[0].Rows[i]["CookbookId"].ToString() + "\",\"CookingNumber\":\"" + ds.Tables[0].Rows[i]["CookingNumber"].ToString() + "\",\"DishState\":\"" + ds.Tables[0].Rows[i]["DishState"].ToString() + "\",\"Flag\":\"" + ds.Tables[0].Rows[i]["Flag"].ToString() + "\"},");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("],");
                sb.Append("\"Msg\":\"\",\"Url\":\"\"");
                sb.Append("}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"没有查询到相关数据！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    private string getCookList_Bak(string Flag)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select r.Id as OrderId,s.DishId,s.CName,s.Num,case when s.Num > 1 then '('+CONVERT(varchar(2),s.Num)+'份)' else null end Copies,r.Name,s.DishState,s.CookChef,s.DishName,s.CookbookId,s.CookingNumber,CONVERT(varchar(100), s.OrderConfirmtime, 20) OrderConfirmtime ");
            strSql.Append("from (select r.Id,r.U_Id,r.H_Id,t.Name from D_Order r,H_Hotel_Seat t where r.H_Id=t.HotelId and r.DineTable=t.Id) r ");
            strSql.Append("left join (select a.*,b.DishId,b.DishName,b.DishState,b.OrderConfirmtime,b.CookWeight,b.TimeWeight,b.PressWeight,b.CookChef,y.RoleId,k.Id as CookbookId,k.CookingNumber,b.Createtime from D_Order_Details a,D_CuiCai b,H_Hotel_Cookbook k,H_Hotel_CookbookCategory y where a.Id=b.DishId and a.OrderId=b.OrderId and a.HCId=k.Id and k.CategoryId=y.Id) s ");
            strSql.Append("on r.Id = s.OrderId ");
            strSql.Append("and r.U_Id = s.UId ");
            strSql.Append("where s.DishState in (10) ");
            strSql.Append("and r.H_Id = '" + Session[CookieHelp.SESSION_HotelId] + "' ");
            //根据用户部门角色获取不同菜品数据
            if (!string.IsNullOrEmpty(Session[CookieHelp.SESSION_DeptId].ToString()))
            {
                strSql.Append("and s.RoleId = '" + Session[CookieHelp.SESSION_DeptId].ToString() + "' ");
            }

            bool flag = true;
            if (Flag == "Urgent")
            {
                flag = false;
                strSql.Append("and s.DishState = 10 ");
                //strSql.Append("and (s.CookWeight+s.PressWeight+DATEDIFF(minute,s.Createtime,getdate()))>100 ");
            }
            else if (Flag == "General")
            {
                strSql.Append("and s.DishState = 2 ");
                //strSql.Append("and (s.CookWeight+s.PressWeight+DATEDIFF(minute,s.Createtime,getdate()))<=100 ");
            }
            strSql.Append("order by s.CookWeight+s.PressWeight+DATEDIFF(minute,s.Createtime,getdate()),s.Price desc ");

            string sql = string.Empty;
            DataSet dt = new DataSet();
            if (flag)
            {
                sql = @"select s.CName,s.DishState,s.CookChef,s.DishName,s.CookbookId,s.CookingNumber,CONVERT(varchar(100), s.OrderConfirmtime, 20) OrderConfirmtime from 
                        (select r.Id,r.U_Id,r.H_Id,t.Name from D_Order r,H_Hotel_Seat t where r.H_Id=t.HotelId and r.DineTable=t.Id) r 
                        left join (select a.*,b.DishId,b.DishName,b.DishState,b.OrderConfirmtime,b.CookWeight,b.TimeWeight,b.PressWeight,b.CookChef,y.RoleId,k.Id as CookbookId,k.CookingNumber 
                        from D_Order_Details a,D_CuiCai b,H_Hotel_Cookbook k,H_Hotel_CookbookCategory y 
                        where a.Id=b.DishId and a.OrderId=b.OrderId and a.HCId=k.Id and k.CategoryId=y.Id) s 
                        on r.Id = s.OrderId and r.U_Id = s.UId where s.DishState in (2) and r.H_Id = '" + Session[CookieHelp.SESSION_HotelId] + @"' 
                        group by s.CName,s.DishState,s.CookChef,s.DishName,s.CookbookId,s.CookingNumber,CONVERT(varchar(100), s.OrderConfirmtime, 20)";
                dt = DbHelperSQL.Query(sql);
            }
            

            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            StringBuilder sb = new StringBuilder();
            if (ds.Tables[0].Rows.Count > 0 || ((System.Data.InternalDataCollectionBase)(dt.Tables)).Count > 0)
            {
                if (ds.Tables[0].Rows.Count == 0 && dt.Tables[0].Rows.Count == 0)
                {
                    sb.Append("{\"Success\":false,\"Msg\":\"没有查询到相关数据！\",\"Url\":\"\"}");
                }
                else
                {
                    int total = 0;
                    if (((System.Data.InternalDataCollectionBase)(dt.Tables)).Count > 0)
                    {
                        total = (Convert.ToInt32(ds.Tables[0].Rows.Count) + Convert.ToInt32(dt.Tables[0].Rows.Count));
                    }
                    else
                    {
                        total = Convert.ToInt32(ds.Tables[0].Rows.Count);
                    }
                    sb.Append("{\"Success\":true,\"Total\":\"" + total + "\",");
                    sb.Append("\"List\":[");
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        sb.Append("{\"OrderId\":\"" + ds.Tables[0].Rows[i]["OrderId"].ToString() + "\",\"DishId\":\"" + ds.Tables[0].Rows[i]["DishId"].ToString() + "\",\"CName\":\"" + ds.Tables[0].Rows[i]["CName"].ToString() + "\",\"Copies\":\"" + ds.Tables[0].Rows[i]["Copies"].ToString() + "\",\"Name\":\"" + ds.Tables[0].Rows[i]["Name"].ToString() + "\",\"DishState\":\"" + ds.Tables[0].Rows[i]["DishState"].ToString() + "\",");
                        sb.Append("\"CookChef\":\"" + ds.Tables[0].Rows[i]["CookChef"].ToString() + "\",\"DishName\":\"" + ds.Tables[0].Rows[i]["DishName"].ToString() + "\",\"CookbookId\":\"" + ds.Tables[0].Rows[i]["CookbookId"].ToString() + "\",\"CookingNumber\":\"" + ds.Tables[0].Rows[i]["CookingNumber"].ToString() + "\",\"OrderConfirmtime\":\"" + ds.Tables[0].Rows[i]["OrderConfirmtime"].ToString() + "\"},");
                    }
                    if (((System.Data.InternalDataCollectionBase)(dt.Tables)).Count > 0)
                    {
                        for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
                        {
                            sb.Append("{\"OrderId\":\"\",\"DishId\":\"\",\"CName\":\"" + dt.Tables[0].Rows[i]["CName"].ToString() + "\",\"Copies\":\"\",\"Name\":\"\",\"DishState\":\"" + dt.Tables[0].Rows[i]["DishState"].ToString() + "\",\"CookChef\":\"" + dt.Tables[0].Rows[i]["CookChef"].ToString() + "\",");
                            sb.Append("\"DishName\":\"" + dt.Tables[0].Rows[i]["DishName"].ToString() + "\",\"CookbookId\":\"" + dt.Tables[0].Rows[i]["CookbookId"].ToString() + "\",\"CookingNumber\":\"" + dt.Tables[0].Rows[i]["CookingNumber"].ToString() + "\",\"OrderConfirmtime\":\"" + dt.Tables[0].Rows[i]["OrderConfirmtime"].ToString() + "\"},");
                        }
                    }
                    sb.Remove(sb.Length - 1, 1);
                    sb.Append("],");
                    sb.Append("\"Msg\":\"\",\"Url\":\"\"");
                    sb.Append("}");
                }
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"没有查询到相关数据！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 菜肴烹调
    /// </summary>
    /// <param name="OrderId">订单ID</param>
    /// <param name="DishId">菜品ID</param>
    /// <param name="arrOrderId">订单ID</param>
    /// <param name="arrOrderId">烹调ID</param>
    /// <returns>返回Json数据</returns>
    private string updateCookState2(string OrderId, string DishId, string arrOrderId, string arrDishId)
    {
        if (Session[CookieHelp.SESSION_H_UserName].ToString() == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            List<String> list = new List<string>();

            if (!string.IsNullOrEmpty(arrDishId))
            {
                for (int i = 0; i < arrDishId.Split(',').Length; i++)
                {
                    if (!string.IsNullOrEmpty(arrDishId.Split(',')[i]))
                    {
                        list.Add("update D_Order_Details set State='2' where Id='" + arrDishId.Split(',')[i] + "' and OrderId='" + arrOrderId.Split(',')[i] + "';");
                        list.Add("update D_CuiCai set DishState='2',CookChef='" + Session[CookieHelp.SESSION_H_UserName].ToString() + "',OrderConfirmTime=getdate() where OrderId='" + arrOrderId.Split(',')[i] + "' and DishId='" + arrDishId.Split(',')[i] + "';");
                    }
                }
                list.Add("update D_CuiCai set CookWeight=CookWeight-5,TimeWeight=TimeWeight+DATEDIFF(minute,CreateTime,getdate()) where DishState='10' and DishId not in (" + DishId + ");");
            }
            else
            {
                list.Add("update D_Order_Details set State='2' where Id='" + DishId + "' and OrderId='" + OrderId + "';");
                list.Add("update D_CuiCai set DishState='2',CookChef='" + Session[CookieHelp.SESSION_H_UserName].ToString() + "',OrderConfirmTime=getdate() where OrderId='" + OrderId + "' and DishId='" + DishId + "';");
                list.Add("update D_CuiCai set CookWeight=CookWeight-5,TimeWeight=TimeWeight+DATEDIFF(minute,CreateTime,getdate()) where DishState='10' and OrderId='" + OrderId + "' and DishId<>'" + DishId + "';");
            }

            StringBuilder sb = new StringBuilder();
            int rows = DbHelperSQL.ExecuteSqlTran(list);
            if (rows > 0)
            {
                sb.Append("{\"Success\":true,\"Msg\":\"操作成功！\",\"Url\":\"\"}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 菜肴完成
    /// </summary>
    /// <param name="DishId">菜肴名称</param>
    /// <param name="CookChef">烹调人员</param>
    /// <returns></returns>
    private string updateCookState3(string DishId, string CookChef)
    {
        if (Session[CookieHelp.SESSION_H_UserName].ToString() == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            List<String> list = new List<string>();

            for (int i = 0; i < DishId.Split('|').Length; i++)
            {
                list.Add("update D_Order_Details set State='3' where Id='" + DishId.Split('|')[i] + "' and state=2;");
                list.Add("update D_CuiCai set DishState='3' where CookChef='" + CookChef + "' and DishId='" + DishId.Split('|')[i] + "' and  dishstate=2;");
            }

            StringBuilder sb = new StringBuilder();
            int rows = DbHelperSQL.ExecuteSqlTran(list);
            if (rows > 0)
            {
                sb.Append("{\"Success\":true,\"Msg\":\"操作成功！\",\"Url\":\"\"}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 获取酒店待传菜数据
    /// </summary>
    /// <param name="Flag">数据类别:所有,加急,普通</param>
    /// <returns>返回Json数据</returns>
    private string getDishList(string Flag)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            StringBuilder strSql = new StringBuilder();
            #region 原口径
            //strSql.Append("select r.Id as OrderId,s.DishId,s.CName,s.Num,case when s.Num > 1 then '('+CONVERT(varchar(2),s.Num)+'份)' else null end Copies, ");
            //strSql.Append("'('+r.Dinecondition+')' as Dinecondition,case when r.Dinecondition='大厅' then t.Name+'号桌' else t.Name end DineName ");
            //strSql.Append("from D_Order r ");
            //strSql.Append("left join H_Hotel_Seat t ");
            //strSql.Append("on r.H_Id = t.HotelId ");
            //strSql.Append("and r.DineTable = t.Id ");
            //strSql.Append("left join (select a.*,b.DishId,b.DishState,b.OrderConfirmtime,b.CookWeight,b.PressWeight,b.TimeWeight,b.Createtime from D_Order_Details a,D_CuiCai b where a.Id=b.DishId and a.OrderId=b.OrderId) s ");
            //strSql.Append("on r.Id = s.OrderId ");
            //strSql.Append("and r.U_Id = s.UId ");
            //strSql.Append("where s.DishState = 3 ");
            //strSql.Append("and r.H_Id = '" + Session[CookieHelp.SESSION_HotelId] + "' ");
            //if (Flag != "")
            //{
            //    if (Flag == "Urgent")
            //    {
            //        strSql.Append("and (s.CookWeight+s.PressWeight+DATEDIFF(minute,s.Createtime,getdate()))>100 ");
            //    }
            //    if (Flag == "General")
            //    {
            //        strSql.Append("and (s.CookWeight+s.PressWeight+DATEDIFF(minute,s.Createtime,getdate()))<=100 ");
            //    }
            //}
            //strSql.Append("order by s.CookWeight+s.PressWeight+DATEDIFF(minute,s.Createtime,getdate()),s.Price desc");
            #endregion

            #region 原口径.2015.4.13
//            strSql.Append(@"select 
//                         d.Id as OrderId,
//                         t.DishId,
//                         d.DineTable,
//                         dd.CName,
//                          sum(dd.Num) as Num,
//                          case when sum(dd.Num) > 1 then '('+CONVERT(varchar(2),sum(dd.Num))+'份)' else null end Copies,
//                         '('+d.Dinecondition+')' as Dinecondition,
//                         (select Name from H_Hotel_Seat where Id=d.DineTable) as DineName,
//                          max((c.CookWeight+c.PressWeight+DATEDIFF(minute,c.Createtime,getdate()))) as  Weight,
//                          max(dd.Price) Price
//                         from D_Order d join D_Order_Details dd 
//                        on d.Id=dd.OrderId
//                        join D_CuiCai c on dd.id= c.DishId and dd.OrderId=c.OrderId 
//                        Join (
//	                        select OrderId,DishName ,DishId = stuff((select '|' + CONVERT(varchar(100),DishId) from D_CuiCai t 
//	                        where OrderId = D_CuiCai.OrderId and DishName=D_CuiCai.DishName for xml path('')) , 1 , 1 , '') 
//	                        from D_CuiCai group by OrderId,DishName 
//                         ) t on t.OrderId=d.Id and t.DishName=dd.CName
//                        where c.DishState=3 and d.H_Id='" + Session[CookieHelp.SESSION_HotelId] + "' ");
//            if (Flag != "")
//            {
//                if (Flag == "Urgent")
//                {
//                    strSql.Append("and (c.CookWeight+c.PressWeight+DATEDIFF(minute,c.Createtime,getdate()))>100 ");
//                }
//                if (Flag == "General")
//                {
//                    strSql.Append("and (c.CookWeight+c.PressWeight+DATEDIFF(minute,c.Createtime,getdate()))<=100 ");
//                }
//            }
//            strSql.Append("group by d.Id,d.DineTable,d.Dinecondition,dd.CName,dd.Price,t.DishId ");
//            strSql.Append("order by Weight desc, dd.Price desc");
            #endregion


           //添加and dishstate<>4 
            strSql.Append(@"select d.Id  as OrderId,
                             t.DishId,
                             d.DineTable,
                             t.DishName,
                             sum(t.Num) as Num,
                             sum(t.Weight) Weight,
                             case when t.Unit='斤' then (case when sum(t.Weight)<>'0.00' then '('+CONVERT(varchar(10),sum(t.Weight))+t.Unit+')' else null end)
                             else (case when sum(t.Num) > 1 then '('+CONVERT(varchar(2),sum(t.Num))+t.Unit+')' else null end) end Copies,
                             SUM(t.Price) as Price,
                             (select Name from H_Hotel_Seat where HotelId=d.H_Id and Id=d.DineTable) as DineName,
                             '('+d.Dinecondition+')' as Dinecondition,
                             t.CookWeight,
                             t.IsDisplay
                             from D_Order d 
                             Join (
	                            select i.OrderId,i.DishState,i.DishName,sum(s.Num) Num,sum(s.Weight) Weight,sum(s.Price) Price,k.Unit,
	                            max((i.CookWeight+i.PressWeight+DATEDIFF(minute,i.Createtime,getdate()))) CookWeight,
	                            case StartIdentification when  0 then 1 else y.IsDisplay end  as IsDisplay,DishId = stuff((select '|' + CONVERT(varchar(100),DishId) from D_CuiCai t 
	                            where OrderId = i.OrderId and DishName=i.DishName and dishstate<>4  for xml path('')) , 1 , 1 , '') 
	                            from D_CuiCai i,D_Order_Details s,H_Hotel_Cookbook k,H_Hotel_CookbookCategory y 
	                            where i.DishId=s.Id and i.OrderId=s.OrderId and s.HCId=k.Id and k.CategoryId=y.Id and i.DishState=3
	                            group by i.OrderId,i.DishState,i.DishName,s.Num,k.Unit,y.IsDisplay ,StartIdentification
                             ) t on t.OrderId=d.Id 
                            where d.H_Id='" + Session[CookieHelp.SESSION_HotelId] + "' ");
            if (Flag != "")
            {
                if (Flag == "Urgent")
                {
                    strSql.Append("and t.CookWeight > 100 ");
                }
                if (Flag == "General")
                {
                    strSql.Append("and t.CookWeight <= 100 ");
                }
            }
            strSql.Append("group by d.H_Id,d.Id,d.DineTable,d.Dinecondition,t.DishName,t.Unit,t.DishState,t.CookWeight,t.Price,t.IsDisplay,t.DishId ");
            strSql.Append("order by t.CookWeight desc, t.Price desc");

            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            StringBuilder sb = new StringBuilder();
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append("{\"Success\":true,\"Total\":\"" + ds.Tables[0].Rows.Count + "\",");
                sb.Append("\"List\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    sb.Append("{\"OrderId\":\"" + ds.Tables[0].Rows[i]["OrderId"].ToString() + "\",\"DishId\":\"" + ds.Tables[0].Rows[i]["DishId"].ToString() + "\",\"DishName\":\"" + ds.Tables[0].Rows[i]["DishName"].ToString() + "\",\"Num\":\"" + ds.Tables[0].Rows[i]["Num"].ToString() + "\",");
                    sb.Append("\"Copies\":\"" + ds.Tables[0].Rows[i]["Copies"].ToString() + "\",\"Dinecondition\":\"" + ds.Tables[0].Rows[i]["Dinecondition"].ToString() + "\",\"DineName\":\"" + ds.Tables[0].Rows[i]["DineName"].ToString() + "\",\"IsDisplay\":\"" + ds.Tables[0].Rows[i]["IsDisplay"].ToString() + "\"},");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("],");
                sb.Append("\"Msg\":\"\",\"Url\":\"\"");
                sb.Append("}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"没有查询到相关数据！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 传菜
    /// </summary>
    /// <param name="OrderId">订单ID</param>
    /// <param name="DishId">菜品ID</param>
    /// <returns>返回Json数据</returns>
    private string updateDishState(string OrderId, string DishId, string Num, string IsDisplay)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            List<String> list = new List<string>();

            if (IsDisplay == "1")
            {
                string Dishid = string.Empty;
                for (int t = 0; t < Convert.ToInt32(Num); t++)
                {
                    Dishid += DishId.Split('|')[t] + "|";
                }
                DishId = Dishid.Remove(Dishid.Length - 1);
            }

            for (int i = 0; i < DishId.Split('|').Length; i++)
            {
                list.Add("update D_Order_Details set State='4' where Id='" + DishId.Split('|')[i] + "' and OrderId='" + OrderId + "';");
                list.Add("update D_CuiCai set DishState='4' where OrderId='" + OrderId + "' and DishId='" + DishId.Split('|')[i] + "';");
            }

            StringBuilder sb = new StringBuilder();
            if (list.Count > 0)
            {
                int rows = DbHelperSQL.ExecuteSqlTran(list);
                if (rows > 0)
                {
                    sb.Append("{\"Success\":true,\"Msg\":\"操作成功！\",\"Url\":\"\"}");
                }
                else
                {
                    sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\"}");
                }
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 获取可换的桌位信息
    /// </summary>
    /// <param name="OrderId">订单ID</param>
    /// <param name="DineTableId">现桌位号</param>
    /// <returns>口径:换桌时,取H_Hotel_Seat表Status(0)字段或者D_Order表在"预定时间"加"默认延时时间"后之外的餐桌;</returns>
    private string getDineTable(string OrderId, string DineTableId)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select t.Id DineTableId,t.Category,t.Name,t.Numbers from H_Hotel_Seat t ");
            strSql.Append("left join (select a.H_Id,a.Id,a.DineTable,a.OrderTime,DATEADD(MI,a.RetentionTime,a.OrderTime) DelayDate ");
            strSql.Append("from ( select r.H_Id,r.Id,r.DineTable,r.OrderTime,isnull(g.RetentionTime,'30') RetentionTime ");
            strSql.Append("from D_Order r ");
            strSql.Append("left join H_Hotel_Setting g ");
            strSql.Append("on r.Id = g.HotelId ");
            strSql.Append("where r.OrderState in ('1','2')) a) r ");
            strSql.Append("on t.HotelId=r.H_Id ");
            strSql.Append("and r.OrderTime>r.DelayDate ");
            strSql.Append("and r.Id<>'" + OrderId + "' ");
            strSql.Append("and r.DineTable<>'" + DineTableId + "' ");
            strSql.Append("where t.Status='0' and t.HotelId='" + Session[CookieHelp.SESSION_HotelId] + "' ");

            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            StringBuilder sb = new StringBuilder();
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append("{\"Success\":true,\"Total\":\"" + ds.Tables[0].Rows.Count + "\",");
                sb.Append("\"List\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    sb.Append("{\"DineTableId\":\"" + ds.Tables[0].Rows[i]["DineTableId"].ToString() + "\",\"Category\":\"" + ds.Tables[0].Rows[i]["Category"].ToString() + "\",\"Name\":\"" + ds.Tables[0].Rows[i]["Name"].ToString() + "\",\"Numbers\":\"" + ds.Tables[0].Rows[i]["Numbers"].ToString() + "\"},");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("],");
                sb.Append("\"Msg\":\"\",\"Url\":\"\"");
                sb.Append("}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"没有可换的桌位！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 换桌管理
    /// </summary>
    /// <param name="OrderId">订单ID</param>
    /// <param name="DineTableId">原来桌位ID</param>
    /// <param name="newDineTableId">新桌位ID</param>
    /// <returns>返回Json数据</returns>
    private string updateOrderDineTable(string OrderId, string DineTableId, string newDineTableId)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            List<String> list = new List<string>();

            list.Add("update D_Order set DineTable = '" + newDineTableId + "' where Id='" + OrderId + "' and DineTable='" + DineTableId + "';");
            list.Add("update D_CuiCai set DineTable='" + newDineTableId + "' where  OrderId='" + OrderId + "' and DineTable='" + DineTableId + "';");
            list.Add("update H_Hotel_Seat set Status = '0' where Id='" + DineTableId + "' and HotelId='" + Session[CookieHelp.SESSION_HotelId] + "';");
            list.Add("update H_Hotel_Seat set Status = '1' where Id='" + newDineTableId + "' and HotelId='" + Session[CookieHelp.SESSION_HotelId] + "';");

            StringBuilder sb = new StringBuilder();
            int rows = DbHelperSQL.ExecuteSqlTran(list);
            if (rows > 0)
            {
                sb.Append("{\"Success\":true,\"Msg\":\"操作成功！\",\"Url\":\"\"}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 获取就餐桌位列表(服务员)
    /// </summary>
    /// <param name="Flag">桌位类型</param>
    /// <returns>返回Json数据</returns>
    private string getDineTableList(string Flag)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select t.U_Id,t.OrderId,t.DineTableId,t.Name,t.Category,t.RoomNumber,s.TotalPrice,s.TableState,t.OrderState,t.CreateTime  from ( ");
            strSql.Append("select r.H_Id,r.Id OrderId,r.OrderState,r.U_Id,t.Id DineTableId,t.Name,t.Category,t.RoomNumber,CONVERT(varchar(16),r.CreateTime) CreateTime from D_Order r,H_Hotel_Seat t ");
            strSql.Append("where r.H_Id = t.HotelId ");
            strSql.Append("and r.DineTable = t.Id ");
             strSql.Append("and t.Status <> 0 ");
            strSql.Append("and r.OrderState in (4,5,7) and r.Id in( select MAX(id) from D_Order where H_Id=r.H_Id and DineTable=r.DineTable group by DineTable ) ) t ");
            strSql.Append("left join (select a.OrderId,sum(a.Num*a.Price) as TotalPrice,case when count(*)*4=sum(b.DishState) then 0 else 1 end TableState from D_Order_Details a,D_CuiCai b where a.Id=b.DishId and a.OrderId=b.OrderId group by a.OrderId) s ");
            strSql.Append("on t.OrderId=s.OrderId ");
            strSql.Append("where t.H_Id = '" + Session[CookieHelp.SESSION_HotelId] + "' ");
            if (Flag != "")
            {
                if (Flag == "Rooms")
                {
                    Flag = "包间";
                }
                if (Flag == "Hall")
                {
                    Flag = "大厅";
                }
                strSql.Append(" and t.Category='" + Flag + "' ");
            }
            strSql.Append("  order by Name,OrderId desc ");

            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            StringBuilder sb = new StringBuilder();
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append("{\"Success\":true,\"Total\":\"" + ds.Tables[0].Rows.Count + "\",\"HotelId\":\"" + Session[CookieHelp.SESSION_HotelId] + "\",");
                sb.Append("\"List\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    sb.Append("{\"U_Id\":\"" + ds.Tables[0].Rows[i]["U_Id"].ToString() + "\",\"OrderId\":\"" + ds.Tables[0].Rows[i]["OrderId"].ToString() + "\",\"DineTableId\":\"" + ds.Tables[0].Rows[i]["DineTableId"].ToString() + "\",\"Name\":\"" + ds.Tables[0].Rows[i]["Name"].ToString() + "\",\"Category\":\"" + ds.Tables[0].Rows[i]["Category"].ToString() + "\",");
                    sb.Append("\"RoomNumber\":\"" + ds.Tables[0].Rows[i]["RoomNumber"].ToString() + "\",\"TotalPrice\":\"" + ds.Tables[0].Rows[i]["TotalPrice"].ToString() + "\",\"CreateTime\":\"" + ds.Tables[0].Rows[i]["CreateTime"].ToString() + "\",\"TableState\":\"" + ds.Tables[0].Rows[i]["TableState"].ToString() + "\",\"OrderState\":\"" + ds.Tables[0].Rows[i]["OrderState"].ToString() + "\"},");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("],");
                sb.Append("\"Msg\":\"\",\"Url\":\"\"");
                sb.Append("}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"没有查询到相关数据！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 清台(服务员,收银员)
    /// </summary>
    /// <param name="OrderId">订单ID</param>
    /// <param name="DineTableId">桌位ID</param>
    /// <returns>返回Json数据</returns>
    private string cleanDineTable(string OrderId, string DineTableId)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            List<String> list = new List<string>();

            list.Add("update H_Hotel_Seat set Status = '0' where Id='" + DineTableId + "' and HotelId='" + Session[CookieHelp.SESSION_HotelId] + "';");

            //清台时间
            list.Add(@"insert into D_OperateRecord([OrderID],[OrderProductId],[OperateType],[OperateDesc],[OperateUserId],[OperateUser],[OperateDate]) values
                                     (" + OrderId + ",0,0,'清台时间',0,'" + Session[CookieHelp.SESSION_H_UserName] + "',getdate());"); 


            StringBuilder sb = new StringBuilder();
            int rows = DbHelperSQL.ExecuteSqlTran(list);
            if (rows > 0)
            {
                sb.Append("{\"Success\":true,\"Msg\":\"操作成功！\",\"Url\":\"\"}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 获取登录人员信息
    /// </summary>
    /// <returns>返回Json数据</returns>
    private string getUserInfo()
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("{\"Success\":true,\"HotelId\":" + Session[CookieHelp.SESSION_HotelId].ToString() + ",\"H_Name\":\"" + Session[CookieHelp.SESSION_H_Name].ToString() + "\",\"H_UserName\":\"" + Session[CookieHelp.SESSION_H_UserName].ToString() + "\",\"RoleName\":\"" + Session[CookieHelp.SESSION_RoleName].ToString() + "\",\"RoleIds\":\"" + Session[CookieHelp.SESSION_RoleIds].ToString() + "\"}");
            return sb.ToString();
        }
    }

    /// <summary>
    /// 获取收银员数据列表(收银员)
    /// </summary>
    /// <param name="Flag">数据类型</param>
    /// <returns></returns>
    private string getCashierList(string Flag)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select t.U_Id,t.OrderId,t.DineTableId,t.Name,t.Category,t.RoomNumber,cast(s.TotalPrice as decimal(10,2)) as TotalPrice,s.TableState,t.OrderState  from ( ");
            strSql.Append("select r.H_Id,r.Id OrderId,r.OrderState,r.U_Id,t.Id DineTableId,t.Name,t.Category,t.RoomNumber,r.CreateTime from D_Order r,H_Hotel_Seat t ");
            strSql.Append("where r.H_Id = t.HotelId ");
            strSql.Append("and r.DineTable = t.Id ");
            strSql.Append("and r.OrderState in (4) ) t ");
            strSql.Append(@"left join (select t.OrderId,sum(t.Num*t.Discount*t.Weight) as TotalPrice, case when count(*)*4=sum(t.DishState) then 0 else 1 end TableState from
                            (select a.OrderId,a.Num,c.Discount,b.DishState,(case when a.Weight=0.00 then 1 else a.Weight end) as Weight
                            from D_Order_Details a,D_CuiCai b,H_Hotel_Cookbook c where a.Id=b.DishId and a.OrderId=b.OrderId and a.HCId=c.Id) t group by t.OrderId) s ");
            strSql.Append("on t.OrderId=s.OrderId ");
            strSql.Append("where t.H_Id = '" + Session[CookieHelp.SESSION_HotelId] + "' and s.TableState='0' ");
            if (Flag != "")
            {
                if (Flag == "Rooms")
                {
                    Flag = "包间";
                }
                if (Flag == "Hall")
                {
                    Flag = "大厅";
                }
                strSql.Append(" and t.Category='" + Flag + "' ");
            }
            strSql.Append(" order by t.CreateTime ");

            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            StringBuilder sb = new StringBuilder();
            if (ds.Tables[0].Rows.Count > 0)
            {
                string Token = string.Empty;
                sb.Append("{\"Success\":true,\"Total\":\"" + ds.Tables[0].Rows.Count + "\",\"HotelId\":\"" + Session[CookieHelp.SESSION_HotelId] + "\",\"UserId\":\"" + Session[CookieHelp.SESSION_H_UID] + "\",\"UserPwd\":\"" + Session[CookieHelp.SESSION_H_UserPwd] + "\",");
                sb.Append("\"List\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    Token = DESEncrypt.Encrypt(ds.Tables[0].Rows[i]["OrderId"].ToString() + Session[CookieHelp.SESSION_HotelId] + Session[CookieHelp.SESSION_H_UID] + Session[CookieHelp.SESSION_H_UserPwd]);
                    sb.Append("{\"U_Id\":\"" + ds.Tables[0].Rows[i]["U_Id"].ToString() + "\",\"OrderId\":\"" + ds.Tables[0].Rows[i]["OrderId"].ToString() + "\",\"DineTableId\":\"" + ds.Tables[0].Rows[i]["DineTableId"].ToString() + "\",\"Name\":\"" + ds.Tables[0].Rows[i]["Name"].ToString() + "\",\"Category\":\"" + ds.Tables[0].Rows[i]["Category"].ToString() + "\",");
                    sb.Append("\"RoomNumber\":\"" + ds.Tables[0].Rows[i]["RoomNumber"].ToString() + "\",\"TotalPrice\":\"" + ds.Tables[0].Rows[i]["TotalPrice"].ToString() + "\",\"TableState\":\"" + ds.Tables[0].Rows[i]["TableState"].ToString() + "\",\"OrderState\":\"" + ds.Tables[0].Rows[i]["OrderState"].ToString() + "\",\"Token\":\"" + Token + "\"},");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("],");
                sb.Append("\"Msg\":\"\",\"Url\":\"\"");
                sb.Append("}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"没有查询到相关数据！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 结账(收银员)
    /// </summary>
    /// <param name="U_Id">用户ID</param>
    /// <param name="OrderId">订单ID</param>
    /// <param name="DineTableId">桌位ID</param>
    /// <param name="TotalPrice">订单总价</param>
    /// <param name="CouponPrice">优惠价格</param>
    /// <returns></returns>
    private string OrderPaying(string U_Id, string OrderId, string DineTableId, string OrderAmount, string DisAmount, string RecAmount, string AccAmount)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            List<String> list = new List<string>();

            int OrderState;
            if (U_Id == "-1")
            {
                OrderState = 7;
            }
            else
            {
                OrderState = 5;
            }

            list.Add("update D_Order set OrderState = '" + OrderState + "',OrderAmount=" + OrderAmount + ",RecAmount=" + RecAmount + ",DisAmount=" + DisAmount + ",AccAmount=" + AccAmount + " where Id='" + OrderId + "' and DineTable='" + DineTableId + "';");

            StringBuilder sb = new StringBuilder();
            int rows = DbHelperSQL.ExecuteSqlTran(list);
            if (rows > 0)
            {
                sb.Append("{\"Success\":true,\"Msg\":\"操作成功！\"}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 订单查询
    /// </summary>
    /// <param name="beginDate">开始日期</param>
    /// <param name="endDate">截止日期</param>
    /// <returns></returns>
    private string getOrderQueryList(string beginDate, string endDate)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            string whereSql = string.Empty;
            if (!string.IsNullOrEmpty(beginDate) && !string.IsNullOrEmpty(endDate))
            {
                whereSql = " and CONVERT(varchar(10), OrderTime, 23) between '" + beginDate + "' and '" + endDate + "'";
            }
            if (!string.IsNullOrEmpty(beginDate) && string.IsNullOrEmpty(endDate))
            {
                whereSql = " and CONVERT(varchar(10), OrderTime, 23) between '" + beginDate + "' and '" + beginDate + "'";
            }

            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select Id,OrderState,OrderChannel,CONVERT(varchar(100), OrderTime, 20) OrderTime,
                            case when OrderState='-1' then '下单' when OrderState='1' then '点餐' 
                            when OrderState='2' then '预定成功' when OrderState='3' then '订单取消' 
                            when OrderState='4' then '就餐'  when OrderState='5' then '待评论'  
                            when OrderState='6' then '已评论' when OrderState='7' then '已结账' end StateName,
                            Dinecondition,DineTable,(select Name from H_Hotel_Seat where Id=DineTable) as DineName from D_Order where H_Id='" + Session[CookieHelp.SESSION_HotelId] + "' " + whereSql + " order by OrderTime desc");

            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            StringBuilder sb = new StringBuilder();
            string OrderState = string.Empty;
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append("{\"Success\":true,\"Total\":\"" + ds.Tables[0].Rows.Count + "\",");
                sb.Append("\"List\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i]["OrderState"].ToString() == "2")
                    {
                        OrderState = "tbldetail";
                    }
                    else if (ds.Tables[0].Rows[i]["OrderState"].ToString() == "4")
                    {
                        OrderState = "tbldetails";
                    }
                    sb.Append("{\"Id\":\"" + ds.Tables[0].Rows[i]["ID"].ToString() + "\",\"OrderState\":\"" + OrderState + "\",\"OrderChannel\":\"" + ds.Tables[0].Rows[i]["OrderChannel"].ToString() + "\",\"OrderTime\":\"" + Convert.ToDateTime(ds.Tables[0].Rows[i]["OrderTime"]).ToString("MM-dd hh:ss") + "\",");
                    sb.Append("\"StateName\":\"" + ds.Tables[0].Rows[i]["StateName"].ToString() + "\",\"Dinecondition\":\"" + ds.Tables[0].Rows[i]["Dinecondition"].ToString() + "\",\"DineTable\":\"" + ds.Tables[0].Rows[i]["DineTable"].ToString() + "\",\"DineName\":\"" + ds.Tables[0].Rows[i]["DineName"].ToString() + "\"},");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("],");
                sb.Append("\"Msg\":\"\",\"Url\":\"\"}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"没有查询到相关数据！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 修改时价信息
    /// </summary>
    /// <param name="OrderId"></param>
    /// <param name="DineTableId"></param>
    /// <returns></returns>
    private string UpdateNum(string DetailId, string Num)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            List<String> list = new List<string>();

            list.Add("update D_Order_Details set Weight='" + Convert.ToDouble(Num) + "' where Id=" + DetailId + ";");

            StringBuilder sb = new StringBuilder();
            int rows = DbHelperSQL.ExecuteSqlTran(list);
            if (rows > 0)
            {
                sb.Append("{\"Success\":true,\"Msg\":\"操作成功！\",\"Url\":\"\"}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 订单菜品确认
    /// </summary>
    /// <param name="OrderId">订单ID</param>
    /// <returns></returns>
    private string setCookbook(string OrderId)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            List<String> list = new List<string>();

            list.Add("UPDATE D_Order_Details SET State = CASE WHEN (select case StartIdentification when  0 then 1 else isdisplay END as IsDisplay from H_Hotel_Cookbook c,H_Hotel_CookbookCategory cc where c.CategoryId=cc.Id and c.Id=HCId)=0 THEN 10 ELSE 3 END where State=1 and OrderId=" + OrderId + ";");
            list.Add("UPDATE D_CuiCai SET DishState = CASE WHEN (select case StartIdentification when  0 then 1 else isdisplay END as IsDisplay from H_Hotel_Cookbook c,H_Hotel_CookbookCategory cc,D_Order_Details s where c.CategoryId=cc.Id and c.Id=s.HCId and s.Id=DishId)=0 THEN 10 ELSE 3 END where DishState=1 and OrderId=" + OrderId + ";");

            StringBuilder sb = new StringBuilder();
            int rows = DbHelperSQL.ExecuteSqlTran(list);
            if (rows > 0)
            {
                sb.Append("{\"Success\":true,\"Msg\":\"操作成功！\",\"Url\":\"\"}");
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"操作失败！\",\"Url\":\"\"}");
            }
            return sb.ToString();
        }
    }

    /// <summary>
    /// 绑定注册用户
    /// </summary>
    /// <param name="OrderId"></param>
    /// <returns></returns>
    private string setBindUser(string OrderId, string Mobile)
    {
        if (Session[CookieHelp.SESSION_HotelId] == null)
        {
            return "{\"Success\":false,\"Msg\":\"登录已超时，请点击“确定”按钮重新登录！\",\"Url\":\"login.html\"}";
        }
        else
        {
            string strSql = "select * from U_User where Status='1' and Mobile='" + Mobile + "'";
            DataSet ds = DbHelperSQL.Query(strSql);
            StringBuilder sb = new StringBuilder();
            if (ds.Tables[0].Rows.Count > 0)
            {
                List<String> list = new List<string>(); 
                list.Add("update D_Order set U_Id=(select Id from U_User where Status='1' and Mobile='" + Mobile + "') where D_Order.Id='" + OrderId + "';"); 
                int rows = DbHelperSQL.ExecuteSqlTran(list);
                if (rows > 0)
                {
                    sb.Append("{\"Success\":true,\"Msg\":\"绑定成功！\",\"Url\":\"\"}");
                }
                else
                {
                    sb.Append("{\"Success\":false,\"Msg\":\"绑定失败！\",\"Url\":\"\"}");
                }
            }
            else
            {
                sb.Append("{\"Success\":false,\"Msg\":\"绑定失败！此手机号码未注册！\",\"Url\":\"\"}");
            } 
            return sb.ToString();
        }
    }
}